I have this strange error, when I try to delete a file inside a compressed directory :
JavaScript
x
ZipArchive::close(): Renaming temporary file failed: Permission denied in /MyDirectory/myphpscript.php
Here is my code :
JavaScript
<?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?
Advertisement
Answer
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 !