Search code examples
phphtmlapachepermissionsphp-ziparchive

APACHE Permissions are all set but still don't have permission


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.sstatic.net/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

Solution

  • 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