This article mainly introduces php's function of compressing and downloading website files in batches. It provides an example of compressing files into zip format. If you are interested, refer
This article mainly introduces php's function of compressing and downloading website files in batches. It provides an example of compressing files into zip format. If you are interested, refer
Use php to compress files in batches and download them. The ZipArchive class will be used in this process. before using this class, you must enable zlib in linux. In windows, you must cancel the comments before php_zip.dll. Below is a simple example of compressing a file into a zip format. For more information about the usage, see php documentation.
<? Php program filename='test.zip '; // The final generated file name (including path) if (file_exists ($ filename) {unlink ($ filename );} // regenerate the file $ zip = new ZipArchive (); if ($ zip-> open ($ filename, ZIPARCHIVE: CREATE )! = TRUE) {exit ('file cannot be opened, or file creation failed');} $ datalist = array ('try. php ', 'zip _ class. php '); foreach ($ datalist as $ val) {if (file_exists ($ val) {$ zip-> addFile ($ val );}} $ zip-> close (); // close if (! File_exists ($ filename) {exit ('file cannot be found '); // even if the file is created, it may still fail}
The above is the idea that php implements bulk compression, packaging, and downloading of all the content. We can also use php to call the shell script of linux to implement this function ,, I hope you can study it.