PHP implementation of multi-file packaging download method

Source: Internet
Author: User
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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.