I used to be able to create dynamic zip files just fine with this:
if(isset($_POST['files'])) {
$zip = new ZipArchive();
$zip_name = $_POST['name'].".zip";
if($zip->open($zip_name, ZIPARCHIVE::CREATE)===TRUE) {
foreach($_POST['files'] as $file){
//here $file is like 'path/to/file.pdf' with no special characters in the name
$name = basename($file);
if(file_exists($file)){
$zip->addFile($file, $name);
}
}
$zip->close();
if(file_exists($zip_name)) {
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
readfile($zip_name);
unlink($zip_name);
}
}
}
But now it creates invalid zip files. In windows you get an error message, on mac you get a never ending zip file loop. I've tried a lot of different suggestions on other questions (including the addFromSting
method) but I haven't found a solution.
Thank-you