Home > Software engineering >  PHPExcel Codeigniter-4 unable to upload more than 50k rows
PHPExcel Codeigniter-4 unable to upload more than 50k rows

Time:12-08

I want to upload an excel file of 50K rows but it's unable to read them while I upload 2k row its worked fine and data was uploaded in the database(MySQL) also but when I tried to upload 50K rows at a time its not even showing error also.So my requirement is to upload 50K rows and 40 columns at a time using SpreadsheetReader_XLSX

CodePudding user response:

Sample code:

$content = ""; //$content value is null when creating
for($i=0;$i<10;$i  ){//runs ten times
   //set $content for ten times
   $content .= "John,Doe,2021,12,07,".time().",".$i."\n";
}
$myfile = fopen("myexcel.csv", "a");
fwrite($myfile, $content);
fclose($myfile);

output excel (.csv) :

Sample: :

CodePudding user response:

You are getting error because of memory limit issue of php/mysql. For solving this issue you can chunk your excel file and upload it to database. Follow the below code as reference.

$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);
        //print_r($data);
        $query="INSERT INTO StudentData(FirstName,LastName,MobileNo,City)VALUES('".$data[0]."','".$data[1]."','".$data[2]."','".$data[3]."')";
        //use prepare statement for inserting data by pdo/mysqli prepare
    }
    fclose($handle);
}
  • Related