'ZipArchive::close(): Failure to create temporary file: Permission denied nginx

I would love a good suggestion how to fix the following. For a platform I have to create php word documents and it so happens that on the Apache dev environment this code executes perfectly; yet on the nginx platform I keep on receiving the error as the topic suggests:

ZipArchive::close(): Failure to create temporary file: Permission denied

The build up is pretty simple:

$phpWord = new \PhpOffice\PhpWord\PhpWord();

//code block as in the documentation

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord,'Word2007');

$objWriter->save('doorverwijzing_patient_xxxxxxxxxx.docx');

Where do I change these permissions in the nginx folder structrue to be able to create these documents?



Solution 1:[1]

Had the same issue happen to me, for like 3 hours trying to resolve only to find out that problems was not in the code, problem was in the name of the file I was trying to save. Make sure the file name has no special characters

Solution 2:[2]

It seemed that the upload directory was pointing to was on the root folder. This folder has no external writing rights for security sake. After altering the storage folder to (symbolic link) .private/upload/ the error seemed to be fixed.

Maybe this can help someone else.

Solution 3:[3]

I got this error because I didn't have the folder in which I was trying to write.

Solution 4:[4]

I solve this error it is path issue.

$objWriter->save('/your_project_folder/doorverwijzing_patient_xxxxxxxxxx.docx');

Solution 5:[5]

I solved this problem by full path to save file and some permission! Like that

$objWriter->save('/var/www/project/storage/documents/file.docx');

If you work with Laravel just use public_path('storage/documents/file.docx');

And most important is to check permissions on this folder for www-data

I made www-data the owner of this folder 'documents'

sudo chown –R www-data /var/www/project/storage/documents

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 my_name_is_njuno
Solution 2 P070
Solution 3 Abhi
Solution 4 Rahul Brahmbhatt
Solution 5 ??????