PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.34k stars 3.46k forks source link

Writer/BaseWriter.php: failed to open stream: Permission denied #2372

Closed magicua closed 2 years ago

magicua commented 3 years ago

Hello.

This is a bug report

I am getting the following error:
[2021-11-05 15:18:37] production.ERROR: fopen(/var/www/applications/.../storage/framework/laravel-excel/laravel-excel-scZOjOuy25S7MOmMyXnRYzntkoCoLJxZ.xlsx): failed to open stream: Permission denied {"exception":"[object] (ErrorException(code: 0): fopen(/var/www/applications/.../storage/framework/laravel-excel/laravel-excel-scZOjOuy25S7MOmMyXnRYzntkoCoLJxZ.xlsx): failed to open stream: Permission denied at /var/www/applications/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/BaseWriter.php:123) [stacktrace]

0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'fopen(/var/www/...', '/var/www/applic...', 123, Array)

1 /var/www/applications/.../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/BaseWriter.php(123): fopen('/var/www/applic...', 'wb+')

but the rights to the file are correct: -rw-r--r-- 1 www-data www-data 0 Nov 5 13:15 /var/www/applications/.../storage/framework/laravel-excel/laravel-excel-scZOjOuy25S7MOmMyXnRYzntkoCoLJxZ.xlsx

probably the problem is in the file phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/BaseWriter.php in the line 118 $mode = 'wb+';

I think it is necessary to write: $mode = 'w+b';

because the documentation states: https://www.php.net/manual/en/function.fopen.php To use these flags, specify either 'b' or 't' as the last character of the mode parameter.

scarneros commented 2 years ago

Facing the same issue on Ubuntu 20.04 server, this solution worked for me:

https://unix.stackexchange.com/questions/503111/group-permissions-for-root-not-working-in-tmp

oleibman commented 2 years ago

PR 2657, which I hope will resolve this problem, was just merged. If you have a way to test against master, please do so.

oleibman commented 2 years ago

No update in 4 months. I believe it is fixed. Closing.

pmediavictor commented 1 year ago

Any updates here? I am having same issue.

oleibman commented 1 year ago

The code which was believed responsible was changed over a year ago. If you are having a problem, please open a new issue with your particular details.