I need to upload xls files and their read for insertion into db, if a file reaches megabytes always the message is returned to me:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in
Code for reading xls
require('library/php-excel-reader/excel_reader2.php');
require('library/SpreadsheetReader.php');
$inputFileName = '/home/uploads/'.$nome_arquivo;
$header = 'Conta';
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
//Get worksheet and built array with first row as header
$objWorksheet = $objPHPExcel->getActiveSheet();
//excel with first row header, use header as key
if($header){
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null, true, true, true);
$headingsArray = $headingsArray[1];
$r = -1;
$namedDataArray = array();
for ($row = 2; $row <= $highestRow; ++$row) {
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
++$r;
foreach($headingsArray as $columnKey => $columnHeading) {
$namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
}
}
}
}
else{
//excel sheet with no header
$namedDataArray = $objWorksheet->toArray(null,true,true,true);
}
The error always returns on the line:
$namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
that is within foreach
.
I've added it at the beginning of the file:
set_time_limit(0);
ini_set('memory_limit', '2024M');
Unsuccessful