This article mainly introduces the PHP online packaging download function implementation method, combined with the example form analysis of PHP package download implementation process and related considerations, the need for friends can refer to the following
Last night, in order to get this package download thing, the thing is burnt. There are a few problems, the first one is to start php_zip.dll problem. As long as the php.ini inside the extend_dir inside of the former ";" The number is removed. Restart IIS or Apache.
The problem is that the real php.ini of the system configuration is not always found.
PHP configuration Diagram
The second one is to tell you the path to the configuration document, just press to find it. I had a funny head and wasted a lot of time.
Once you've opened the Php_zip extension library, you're ready to start packing and downloading.
$filename = Date ("Ymdhis"), $zip = new ziparchive ();//Use this class, Linux need to turn on Zlib,windows to cancel Php_zip.dll before the comment $zip->open ($ FileName. ". 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 variable $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 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 that the file size @readfile ($filename. "). Zip ");
The above code basically can be implemented to download the document package, but also solve the Chinese document can not be packaged download problems.
Summary: The above is the entire content of this article, I hope to be able to help you learn.