0

I tried to use ZipArchive to download multiple files with this code recommended in this post

$files = array('readme.txt', 'test.html', 'image.gif');
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFile($file);
}
$zip->close();

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);

But it didn't work. Yes, it did create a zip-file but when I tried to extract it I got message that the archive is not readable and the archive may not be valid or its table of content could be encrypted. What's wrong?

1 Answers1

0

I solved that the problem was the last 4 rows. Instead of that I used header('location: /' . $zipname); and it worked fine!