I have to upload excel and read data then writing to DB. I need to get data from 2mb excel file. I have done coding up to reading excel data. While uploading excel there was shown some issues
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes)
I have solved this by using
ini_set('memory_limit', '-1');
and also execution time issues that also somehow managed by
set_time_limit(0);
the problem is when I'm trying to upload excel size more than 300kb, it taking too much to complete the execution. Can anyone suggest me best way to read data from excel ? Is there any performance issue if I'm storing the values to an array before inserting to DB ?
Adding my codes here
<?php
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
include('../includes/class_read_xl.php');
$obj_read_xl=new class_read_xl();
if(isset($_POST["upload"])) {
move_uploaded_file($_FILES["ufile"]["tmp_name"], "../uploads/xlsheet/" . $_FILES["ufile"]["name"]);
$file = $_FILES['ufile']['name'];
$inputFileName = '../uploads/xlsheet/'.$file;
//$inputFileName = "test.xls";
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(false);
// Load $inputFileName to a PHPExcel Object
$objPHPExcel = $objReader->load($inputFileName);
$total_sheets=$objPHPExcel->getSheetCount(); // here 4
$allSheetName=$objPHPExcel->getSheetNames(); // array ([0]=>'student',[1]=>'teacher',[2]=>'school',[3]=>'college')
//print_r($allSheetName);
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0); // first sheet
$highestRow = $objWorksheet->getHighestRow(); // here 5
$highestColumn = $objWorksheet->getHighestColumn(); // here 'E'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // here 5
//exit();
$arr_data=array();
for ($row = 1; $row <= $highestRow; ++$row) {
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
$value = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
if(is_array($arr_data) ) {
$arr_data[$row-1][$col]=$value;
}
}
}
print_r($arr_data);
}
?>