PHPExcelを使用して10 KB(40 rows & 18 columns)のサイズの非常に小さいExcelファイルをロードしていますが、常にメモリサイズエラーが発生します。私はファイルサイズが非常に小さいことを知っているので、コードに何か問題がありますが、理解できません。PHP Excelエラー - 許容メモリサイズ134217728 bytes exhausted
ini_set('memory_limit', '-1');
$this->load->library('PHPExcel');
$cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_phpTemp;
$cacheSettings = array(' memoryCacheSize ' => '8MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$data = excelToArray($upload_filename);
私は配列にファイルの内容をロードして変換する機能を使用:
function excelToArray($filePath, $header=true){
//Create excel reader after determining the file type
$inputFileName = $filePath;
/** Identify the type of $inputFileName **/
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
/** Create a new Reader of the type that has been identified **/
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
/** Set read type to read cell data onl **/
$objReader->setReadDataOnly(true);
/** Load $inputFileName to a PHPExcel Object **/
$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->getHighestDataRow();
$highestColumn = $objWorksheet->getHighestDataColumn();
$headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null, true, true, true);
$headingsArray = $headingsArray[1];
$r = -1;
$namedDataArray = array();
for ($row = 3; $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);
}
return $namedDataArray;
}
私はスクリプトが失敗した行を次のようにそれを絞り込んに試してみました:
$objPHPExcel = $objReader->load($inputFileName);
別の重要な点は、このコードはlocalhost上で正常に動作しますが、godaddyサーバーでエラーが発生します。
デバッグヘルプ(「なぜこのコードは動作しませんか?)」には、質問自体に再現するために必要な動作、特定の問題またはエラー、および**最短のコードが含まれている必要があります。明確な問題文がない質問は、他の読者にとって有用ではありません。参照してください:[最小、完全、および検証可能な例を作成する方法](http://stackoverflow.com/help/mcve) – Farside