You can use the ZipArchive class to create a ZIP file and pass it to the client. Something like:
$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();
and pass it:
header('Content-Type: application/zip'); header('Content-disposition: attachment; filename='.$zipname); header('Content-Length: ' . filesize($zipname)); readfile($zipname);
The second line causes the browser to display the download window to the user and asks for the name filename.zip. The third line is optional, but some (mostly old) browsers have problems in certain cases without specifying the size of the content.
cletus Nov 18 '09 at 8:08 2009-11-18 08:08
source share