I'm trying to extract a zip archive in a docker container application running Laravel 9 on PHP 8.1.7 and I'm running into a strange error.
So if you try this code in your controller
$zip = new ZipArchive(); $result = $zip->open("/var/www/html/public/my_archive.zip"); if ($result === TRUE) { $zip->extractTo("/var/www/html/public/my_folder"); } $zip->close();
The files in the archive were extracted correctly, but this error was returned:
Error exception ZipArchive::extractTo(/var/www/html/public/my_folder/my_file.xml): Operation failed: Operation not allowed
If I run the same code in php artisantinker it works.
Does anyone have a solution to this problem?
Doesn't appear to be a permissions related issue, the folder is created with 777 permissions and the files are copied correctly.
edit
root@5899a5badc45:/var/www/html/public/my_folder# ls -lhart * -rwxrwxrwx 1 1000 1000 1.3K Oct 25 12:24 phpunit.xml
Thanks
I encountered the exact same problem. On my end, I encountered this problem because I was extracting files from the directory of my Windows installation.
I mean
/var//html/public/my_folder
is a symbolic link to/mnt/dev/my_folder
from Windows (C: e.g. \dev \my_folder
).Since the file system is different from Linux and Windows, it seems that something specific in the ZipArchive class causes this error.
I fixed this by extracting the files in
/tmp/my_folder
and then moving them to/var//html/public/my_folder
.Hope this helps.