dan3460's avatar

Error Reading Excel File

I just move an application that still in development to an Ububtu server. I have several seeders that read a Excel spreadsheet to seed the tables. I'm getting an error, which to me seems to indicate that the zip program could not write a file. I think is probably a permission problem but don't know where the system is trying to create the file, or i may be completely wrong. Here is the error

   PhpOffice\PhpSpreadsheet\Reader\Exception

  Could not find zip member zip:///var/www/builder/storage/framework/cache/laravel-excel/laravel-excel-0IduDnea5G041ip1JtFArahXQOhppFVa.xlsx#_rels/.rels

  at vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Shared/File.php:159
    155▕
    156▕         if ($zipMember !== '') {
    157▕             $zipfile = "zip://$filename#$zipMember";
    158▕             if (!self::fileExists($zipfile)) {
  ➜ 159▕                 throw new ReaderException("Could not find zip member $zipfile");
    160▕             }
    161▕         }
    162▕     }
    163▕
0 likes
6 replies
LaryAI's avatar
Level 58

The error message suggests that the system is unable to find the zip member. This could be due to a permission issue or a missing dependency. To resolve this issue, you can try the following steps:

  1. Check if the required PHP zip extension is installed. You can do this by running the following command:
php -m | grep zip

If the output is empty, it means the extension is not installed. You can install it by running the following command:

sudo apt-get install php-zip
  1. Check the permissions of the storage directory. Make sure that the web server user has write permissions to the storage directory. You can do this by running the following command:
sudo chown -R www-data:www-data /var/www/builder/storage
sudo chmod -R 775 /var/www/builder/storage

Replace /var/www/builder/storage with the path to your storage directory.

  1. If the above steps do not work, try changing the file format of the Excel spreadsheet to a different format such as CSV or XML.

  2. If none of the above steps work, try using a different library to read the Excel file such as PHPOffice/PhpSpreadsheet.

composer require phpoffice/phpspreadsheet

Then, modify your code to use the new library. Here's an example:

use PhpOffice\PhpSpreadsheet\IOFactory;

$spreadsheet = IOFactory::load('/path/to/excel/file.xlsx');
$worksheet = $spreadsheet->getActiveSheet();
$data = $worksheet->toArray();
bloodykheeng's avatar

@LaryAI This error happens if the excel doesnt exist in the path or when u put an invalid path or the file naming of the filr its self

Snapey's avatar

are you running this from the command line? Maybe your user account does not have permission to write to storage/framework/cache ?

dan3460's avatar

I'm running from the command line. I change the own and permissions as suggested and i got an error message that could not open the log file. i run the seeder with sudo and i got the original message. I will save the file as xls, and see. On my development machine running windows this works fine.

dan3460's avatar
dan3460
OP
Best Answer
Level 8

Update, the problem was the name of the file. On my machine, running window, in the seeder i had written the name of the file with the first letter in capital, the first letter of the actual file was lower case. Updating the name of the file to the correct case solved the problem.

Please or to participate in this conversation.