15

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?

Federico J.
  • 15,388
  • 6
  • 32
  • 51
P070
  • 189
  • 1
  • 1
  • 10

5 Answers5

6

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

  • Damn it! I was getting `ErrorException : ZipArchive::close(): Failure to create temporary file: Protocol error` for hours and couldn't understand the real issue. Thank you – Amirreza Nasiri Dec 07 '19 at 02:56
  • @my_name_is_njune not working your shared solution. Thank you. – Kamlesh Sep 29 '20 at 12:20
3

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.

P070
  • 189
  • 1
  • 1
  • 10
1

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

Abhi
  • 1,127
  • 1
  • 12
  • 25
0

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
-17

Please change the permission of the destination directory in which you save file. Permission must be 0777 for that folder and then it will work fine.