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';
And here's the log:
PHP Warning: ZipArchive::close(): Failure to create temporary file: Permission denied in /var/www/html/test/app/test.php
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