0

I recently faced this issue, as you can see in the picture, I granted all sorts of permissions to all files, but still I get this error.

Here's the code:

$zipdir=dirname(dirname(__FILE__)).'/tmp';
$zipname="$zipdir/$input[user]-".time().'.zip';
list($pdf,$pdfname)=test_pdf($request);
$zip=new ZipArchive();
if ($zip->open($zipname,ZipArchive::CREATE)!==true) return $error='Could not open zip archive for writing';
$zip->addFromString("pdf/$pdfname", $pdf->Output('','S'));
$zip->addFile("test-docs/",$testformname);
$zip->close();
if (!file_exists($zipname)) return $error='Could not create zip archive';

https://i.stack.imgur.com/kmxUg.png

And here's the log:

PHP Warning:  ZipArchive::close(): Failure to create temporary file: Permission denied in /var/www/html/test/app/test.php
Nimantha
  • 6,405
  • 6
  • 28
  • 69
LilRupert
  • 29
  • 9
  • You’ll need to post a short, self-contained example that causes this problem. The error message is pointing potentially not to the zip file, but a temporary folder where it is initially being created, too. – Chris Haas Oct 21 '21 at 03:33
  • Umm, I thought it's pointing to Create, Thanks for the mention. but also i had this problem weeks ago i forgot to say and it just got fixed by itself i couldn't find the solution tho. – LilRupert Oct 21 '21 at 03:39
  • Thanks @LilRupert, so is this resolved and we can close it then? – Chris Haas Oct 21 '21 at 03:42
  • No, i just faced it again, but this time it seems that it doesn't want to get fixed... im really confused about that. i read on some websites and they couldn't find any solution neither... that's because of my poor english knowledge that i forgot to say "Again" in my comment above. – LilRupert Oct 21 '21 at 03:45
  • Can you please post a small code sample, ideally 5 to 10 lines, that causes that exception to be thrown for you? – Chris Haas Oct 21 '21 at 03:48
  • Yeah, sorry if it took time, i was preparing. Question Updated. – LilRupert Oct 21 '21 at 03:54
  • Thanks! Inspect the contents of `$zipname` using `var_dump` or similar. Try skipping ZIP and just use normal file system methods, for instance, `touch` or even better, `is_writable`. – Chris Haas Oct 21 '21 at 03:58
  • Thank you so much Mr.Haas, i'll work on that! – LilRupert Oct 21 '21 at 04:00

1 Answers1

0

Problem just solved!

I needed to grant 775 or above permission to the whole "html" folder in this path :

"/var/www/html/..."

Not just files and folders in it because i tried that completely.

Also apache:apache permission is not needed, root does the work.

This comment helped a lot:

move_uploaded_file gives "failed to open stream: Permission denied" error

LilRupert
  • 29
  • 9