在使用.csv加载38 to的PHPExcel文件时,即使将php memory_limit设置为1024M,也会收到huge text node: out of memory错误。
知道如何加载大型.csv文件吗?
误差
Error loading file "data.csv": Warning: DOMDocument::loadHTMLFile(): xmlSAX2Characters: huge text node: out of memory in /var/www/site/data.csv, line: 264094 in /var/www/site/vendor/CodePlex/PHPExcel/PHPExcel/Reader/HTML.php line 458
PHP代码
ini_set('memory_limit', '1024M');
$inputFileName = '/var/www/site/data.csv';
$phpExcel = new PHPExcel;
// Read your Excel workbook
try
{
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
}
catch(Exception $e)
{
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}php.ini
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M发布于 2013-04-14 16:32:07
您可以使用fgetcsv并逐行加载csv。
$file = '/path/filename.csv';
$f = fopen($file, 'rb');
while( $cols = fgetcsv($f) )
{
// $cols[0]; // first column of the current row
}
fclose($f);发布于 2013-04-14 16:30:40
https://stackoverflow.com/questions/16001267
复制相似问题