0
votes

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
Can you check the return value of $zip->open? .. see docs. - codedge
The return value is true - Marianne_CM8
No I solved that the problem was the last 4 rows. Instead of that I used header('location: /' . $zipname); and it worked fine! - Marianne_CM8
You should post this as an answer and accept it so others can see that your problem was solved, especially if you solved it yourself :) - codedge

1 Answers

0
votes

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