PHP import Excel into database (xls & xlsx)
This is best plugin with proper documentation and examples
https://github.com/PHPOffice/PHPExcel
Plus point: you can ask for help in its discussion forum and you will get response within a day from the author itself, really impressive.
PHP Excel import to MYSQL database working fine on localhost but not on online server
Fatal error: Uncaught Error: Class 'ZipArchive' not found in
/home/rpa16cfpf0mt/public_html/goodluck_sales/adminarea/excel/vendor/SpreadsheetReader_XLSX.php:217
Stack trace: #0
It seems that you have to install the Zip extension.
About zip extension, check the official page
how to import excel file in mysql database using php?
**example for import excel or csv file to mysql database with very easy method.
query:**
- CREATE TABLE IF NOT EXISTS `studentdata`( `StudentID` int(11) NOT
NULL AUTO_INCREMENT, `FirstName` varchar(30) NOT NULL, `LastName`
varchar(30) NOT NULL, `MobileNo` varchar(30) NOT NULL, `City`
varchar(30) NOT NULL, PRIMARY KEY (`StudentID`) ) E
NGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
php
if(isset($_POST['submit']))
{
if($_FILES['csvFile']['name']!="")
{ $fileName=uploadFile($_FILES['excelFile'],array(".csv"),"excel_file");
$row=0;
if(($handle = fopen("excel/".$fileName , "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$num = count($data);
$query="INSERT INTO StudentData(FirstName,LastName,MobileNo,City)
VALUES('".$data[0]."','".$data[1]."','".$data[2]."','".$data[3]."')";
mysql_query($query);
}
fclose($handle);
}
}
else if($_FILES['excelFile']['name']!="")
{
$fileName=uploadFile($_FILES['excelFile'],array(".xls",".xlsx"),"excel_file");
$data = new Spreadsheet_Excel_Reader();
$data->read('excel_file/'.$fileName);
for($i=1;$i<=$data->sheets[0]['numRows'];$i++)
{
$firstname=$data->sheets[0]['cells'][$i][1];
$lastname=$data->sheets[0]['cells'][$i][2];
$mobile=$data->sheets[0]['cells'][$i][3];
$city=$data->sheets[0]['cells'][$i][4];
$query="INSERT INTO StudentData(FirstName,LastName,MobileNo,City)
VALUES('".$firstname."','".$lastname."','".$mobile."','".$city."')";
mysql_query($query);
}
}
}
Import Excel file to MySQL using PHP Yii2
in your code you have used
$inputFileType =\PHPExcel_IOFactory::identify($inputFiles);
which is used to identify the valid excel file and it expects the parameter as filename
.
I can see in your code, you have passed $inputFiles
as a parameter to identify
method, which is not a file name but resource handler. and identify
method expects it to be string (file name).
This is the reason you are getting error.
Note : fopen() returns a file pointer resource on success, or FALSE on error.
$inputFiles = fopen("../file/" . $modelFile->file, "r");
Related Topics
PHP Difference Between Notice and Warning
Request Exceeded the Limit of 10 Internal Redirects
A _Construct on an Eloquent Laravel Model
PHP Password_Verify Not Working with Database
PHP 5 Reflection API Performance
PHP Parsing Problem - &Nbsp; and Â
Create Superglobal Variables in PHP
How to Include Config.PHP Efficiently
PHP Switch Case More Than One Value in the Case
How to Send a Http/2 Post Request in PHP
Which Is Fastest in PHP- MySQL or MySQLi
Can PHP Asynchronously Use Sockets
Codeigniter: How to Do a Select (Distinct Fieldname) MySQL Query
How to Prevent JavaScript Code Theft
How to Measure the Strength of a Password
Randomly Losing Session Variables Only in Google Chrome & Url Rewriting
How to Allow Remote Access to My Wamp Server for Mobile(Android)