I am using ZipArchive:
function zip_dir($source, $target){ $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST); $zip = new \ZipArchive(); if($zip->open($target, \ZipArchive::CREATE) !== true) exit('cannot create zip'); foreach($iterator as $file){ $zip->addFile($file); print $file . '<br>'; } $zip->close(); return $target; } zip_dir(__DIR__ . '/test/', __DIR__ . '/testarchive.zip');
I see a list of files, but in the end I canβt find the zip file that needs to be created. And I have no errors / exceptions from ZipArchive ...
edit:
I added print $zip->getStatusString(); after $zip->close();
and it prints: Cannot open file: Permission denied. "What does this mean? I know for sure that every directory is writable, bc I can create new files with PHP inside them ...
edit 2:
if(is_writable(dirname($target))) print 'target dir is writable...';
it prints this, so the directory is writable. I feel like I'm in the twilight zone ...
file php zip ziparchive
Alex
source share