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.