PHP Online Packaging download features sample _php tips

Source: Internet
Author: User
Tags php online ziparchive

This article describes the implementation of the PHP online packaging download function. Share to everyone for your reference, specific as follows:

Last night, in order to get this package to download the matter, make a mess of things. There are several problems, the first one is to start Php_zip.dll. Saying as long as the php.ini inside the extend_dir inside the front of the ";" Number removed. Restart either IIS or Apache.

The problem is that the real php.ini of the system configuration is always not found.

PHP configuration Diagram

The second is to tell you the path to the configuration document. I was so funny that I wasted a lot of time.

After this opens the Php_zip extension library, you can start packing and downloading.

$filename = Date ("Ymdhis");
$zip = new Ziparchive ()///Using this class, Linux needs to turn on Zlib,windows
$zip->open ($filename. ") before you cancel Php_zip.dll. Zip ", ziparchive::overwrite); $data is the number that is read from the database
foreach ($data as $val) {
   $attachfile = "E:\BYSJ\BYSJ". $val [' fileaddr ']. $val [' filename ' ]; Write hard path, but it is recommended to use PHP environment variables
   $attachfile =iconv ("UTF-8", "GBK", $attachfile);//transcoding, is the key to packaging Chinese documents
   $zip->addfile ($ Attachfile, basename ($attachfile)); Press Stack
}
$zip->close ()//Close
header ("Content-type:text/html;charset=utf-8");/Set page number
header (" Cache-control:public ");
Header ("Content-description:file Transfer");
Header (' Content-disposition:attachment filename= '. basename ($filename)); FileName
Header ("Content-type:application/zip"),
header ("Content-transfer-encoding:binary") in//zip format; Tells the browser that this is the binary
header (' content-length: '. FileSize ($filename));//Tell the browser that the file size
@readfile ($filename. ") Zip ");

The above code can basically implement the document package download, but also solve the Chinese document can not be packaged to download the problem.

More about PHP Interested readers can view the site topics: "Summary of PHP file operations," "PHP Array Operation skills Encyclopedia", "PHP Basic Grammar Primer", "PHP operation and operator Usage Summary", "PHP object-oriented Programming Program", " PHP Network Programming skills Summary, "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design.

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.