This article mainly introduces PHP implementation of multi-file packaging download method, interested in the friend's reference, I hope to help you.
When you need to download multiple files at the same time, most browsers do not support multiple files simultaneous download, you can use JavaScript script to dynamically generate multiple links, but users need to click the Download dialog box, the user experience is not good, and some browsers are not compatible. At this time, multi-file package download to help you solve this problem.
$filename = "Test.zip"; $datalist =array ('./pubfile/1.jpg ', './pubfile/2.jpg '); if (!file_exists ($filename)) {$zip = new Ziparchive (); if ($zip->open ($filename, ziparchive::create) ==true) { foreach ($datalist as $val) { if (file_exists ($val)) { $zip->addfile ($val, basename ($val)); } } $zip->close (); }}if (!file_exists ($filename)) {exit ("Cannot find File");} Header ("Cache-control:public"); Header ("Content-description:file Transfer"); Header (' Content-disposition: Attachment Filename= '. basename ($filename)); FileName header ("Content-type:application/zip"); Header in zip format ("content-transfer-encoding:binary"); Tell the browser that this is the header of the binary file (' content-length: '. FileSize ($filename)); Tell the browser, file size @readfile ($filename);