5

I have this strange error, when I try to delete a file inside a compressed directory :

ZipArchive::close(): Renaming temporary file failed: Permission denied in /MyDirectory/myphpscript.php

Here is my code :

<?php

    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

    $compressedDirectoryPath = '/Users/Shared/SampleZip.zip';

    $zip = new ZipArchive();

    if ($zip->open($compressedDirectoryPath) === true) { 
        if ($zip->deleteName('SampleZip/samplefile.txt') === true) {
            echo 'File deleted';
        } 
    }

    $zip->close(); // the error is pointing here

?>

The echo executes successfully and prints File deleted. I am running a Mac and the permissions on the compressed directory is read & write for all users. What could be the issue?

Nika Kurdadze
  • 2,502
  • 4
  • 18
  • 28

2 Answers2

4

As the error tells you, this is a permission problem. Make sure the apache user (www-data) has the write permission on the directory where the zip archive is.

After that, your code will work as expected.

Good luck !

JazZ
  • 4,469
  • 2
  • 20
  • 40
0

This can also happen when you open the output file on server itself and keep it open while trying to run the script again.

Paul
  • 1
  • Note: answers that are very brief and/or are questions back to the poster should probably be comments. You only need 50 rep points to comment under a question - could you move this there? – Tyler2P Dec 11 '20 at 09:44