PHP online package download function example, php package download example

Source: Internet
Author: User
Tags php online ziparchive

PHP online package download function example, php package download example

This example describes how to implement the PHP online package download function. We will share this with you for your reference. The details are as follows:

Last night, we were so anxious to get this package and download. There are several problems. The first one is the problem of starting PHP_ZIP.dll. Remove the ";" sign in extend_dir of PHP. INI. Restart IIS or apache.

The problem is that the real PHP. INI configured by the system cannot be found.

PHP configuration map

The second is to tell you the path of the configuration document. You can simply find the path. At that time, my head was so funny that I wasted a lot of time.

After enabling the PHP_ZIP extension library, you can start package and download.

$ Filename = date ("YmdHis"); $ zip = new ZipArchive (); // You must enable zlib in linux, for windows, you need to cancel the comments $ zip-> open ($ filename. ". zip ", ZipArchive: OVERWRITE); // $ data is the number foreach ($ data as $ val) read from the database {$ attachfile =" E: \ bysj ". $ val ['fileadd']. $ val ['filename']; // write the hard path, but the PHP environment variable $ attachfile = iconv ("UTF-8", "GBK", $ attachfile) is recommended ); // transcoding is the key to packaging Chinese documents $ zip-> addFile ($ attachfile, basename ($ attachfile); // pressure stack} $ zip-> close (); // close the header ("Content-type: text/html; charset = UTF-8"); // set the page number header ("Cache-Control: public "); header ("Content-Description: File Transfer"); header ('content-disposition: attachment; filename = '. basename ($ filename); // file name header ("Content-Type: application/zip"); // header in zip format ("Content-Transfer-Encoding: binary "); // tell the browser that this is the binary file header ('content-Length :'. filesize ($ filename); // tell the browser the file size @ readfile ($ filename. ". zip ");

The above code can basically be used to package and download documents. It also solves the problem that Chinese documents cannot be downloaded.

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.