Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
magicua opened this issue Nov 5, 2021 · 5 comments
Closed

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

magicua opened this issue Nov 5, 2021 · 5 comments

Comments

@magicua
Copy link

magicua commented Nov 5, 2021

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
Copy link

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 added a commit to oleibman/PhpSpreadsheet that referenced this issue Mar 7, 2022
BaseWriter openFileHandle opens its output file with mode `wb+`. We don't appear to attempt any reads on the file after it is opened in write mode, so `wb` should be sufficient. This may have been a factor in the need for PR PHPOffice#2326, and is likely to be responsible for issue PHPOffice#2372.
oleibman added a commit that referenced this issue Mar 12, 2022
BaseWriter openFileHandle opens its output file with mode `wb+`. We don't appear to attempt any reads on the file after it is opened in write mode, so `wb` should be sufficient. This may have been a factor in the need for PR #2326, and is likely to be responsible for issue #2372.
@oleibman
Copy link
Collaborator

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
Copy link
Collaborator

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

@pmediavictor
Copy link

Any updates here? I am having same issue.

@oleibman
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants