Home  >  Article  >  Backend Development  >  PHP implements batch compression, packaging and downloading of files

PHP implements batch compression, packaging and downloading of files

墨辰丷
墨辰丷Original
2018-06-06 15:19:243448browse

This article mainly introduces the implementation of batch compression, packaging and downloading of files in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.

The code is as follows:

<?php 
$filename=&#39;test.zip&#39;; //最终生成的文件名(含路径) 
if(file_exists($filename)){ 
  unlink($filename); 
} 
//重新生成文件 
$zip=new ZipArchive(); 
if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){ 
  exit(&#39;无法打开文件,或者文件创建失败&#39;); 
} 
$datalist=array(&#39;try.php&#39;,&#39;zip_class.php&#39;); 
foreach($datalist as $val){ 
  if(file_exists($val)){ 
    $zip->addFile($val); 
  } 
} 
$zip->close();//关闭 
if(!file_exists($filename)){ 
  exit(&#39;无法找到文件&#39;); //即使创建,仍有可能失败 
}

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PDO transaction processing methods and example analysis in PHP

Solution to the conflict between __autoload and Smarty in PHP Detailed explanation of the method

Solutions and examples of the garbled problem of PHP using PDO to operate the database

The above is the detailed content of PHP implements batch compression, packaging and downloading of files. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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