Use PHP to implement batch compression, packaging and downloading of files. In this process, the ZipArchive class will be used. Please pay attention before using this class. Linux needs to enable zlib, and windows needs to uncomment php_zip.dll. A simple example of compressing a file into zip format is given directly below. For specific usage, please consult the relevant PHP documentation.
<?php $filename='test.zip'; //最终生成的文件名(含路径) if(file_exists($filename)){ unlink($filename); } //重新生成文件 $zip=new ZipArchive(); if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){ exit('无法打开文件,或者文件创建失败'); } $datalist=array('try.php','zip_class.php'); foreach($datalist as $val){ if(file_exists($val)){ $zip->addFile($val); } } $zip->close();//关闭 if(!file_exists($filename)){ exit('无法找到文件'); //即使创建,仍有可能失败 }
The above is the entire content of PHP to realize batch compression, packaging and downloading of files. We can also use PHP to call the shell script of the Linux system to achieve this function. This is an idea, and I hope you can study it.