PHP implements batch compression download function of website files, _PHP tutorial

WBOY
Release: 2016-07-12 09:06:21
Original
1102 people have browsed it

PHP implements batch compression and downloading of website files.

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.

<&#63;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('无法找到文件'); //即使创建,仍有可能失败 
} 
Copy after login

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1065566.htmlTechArticlephp realizes the batch compression and download function of website files, and uses php to realize batch compression, packaging and downloading of files. In this process, it will be used Go to the ZipArchive class. Please note that before using this class, li...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template