I'm using Laravel excel to import headers & some records.
With this approach, I should able to get headers:
$headings = (new HeadingRowImport)->toArray($myFile);
If $myFile
is a CSV, it's OK; but if I tried with XLS or XLSX (with valid Mimetypes: application/vnd.ms-excel
and application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
, I'm getting such issue:
ZipArchive::getFromName():
Invalid or uninitialized Zip object {"exception":"[object] (ErrorException(code: 0):
ZipArchive::getFromName(): Invalid or uninitialized Zip object at
/var/www/app/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php:308)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'ZipArchive::get...', '/var/www/app/ve...', 308, Array)
#1 /var/www/app/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php(308): ZipArchive->getFromName('_rels/.rels', 0, 1)
#2 /var/www/app/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php(2019): PhpOffice\\PhpSpreadsheet\\Reader\\Xlsx->getFromZipArchive(Object(ZipArchive), '_rels/.rels')
#3 /var/www/app/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php(343): PhpOffice\\PhpSpreadsheet\\Reader\\Xlsx->getWorkbookBaseName(Object(ZipArchive))
#4 /var/www/app/vendor/maatwebsite/excel/src/Reader.php(229): PhpOffice\\PhpSpreadsheet\\Reader\\Xlsx->load('/tmp/laravel-ex...')
#5 /var/www/app/vendor/maatwebsite/excel/src/Reader.php(215): Maatwebsite\\Excel\\Reader->readSpreadsheet()
I have tried to find related bugs but I only found PhpExcel, or PhpSpreadsheet, eg:
- Read Xlsx file in PhpSpreadsheet
- Why am I getting an "invalid or unitialized Zip object" error when trying to read excel file via PHP?
- PHPExcel Warning: ZipArchive::getFromName(): Invalid or unitialized Zip object in
- report bug on PhpSpreadsheet repo > read xlsx using filesystem gaufrette
And I cannot find useful fix from them. Did anyone faced this issue, and how did you fix it ?
My package versions:
- "php": "^7.1.3",
- "laravel/framework": "5.8.*",
- "maatwebsite/excel": "^3.1",
Note that my file has read
permission as it is 644
, and I can open the file with fopen($myFile, 'r')