Home  >  Article  >  Backend Development  >  php实现网站文件批量压缩下载功能,_PHP教程

php实现网站文件批量压缩下载功能,_PHP教程

WBOY
WBOYOriginal
2016-07-12 09:06:211072browse

php实现网站文件批量压缩下载功能,

利用php实现将文件批量压缩打包下载,这个过程中将使用到 ZipArchive 这个类,注意使用该类之前,linux需开启zlib,windows需取消php_zip.dll前的注释。下面直接给出一个简单的将文件压缩为 zip 格式的示例。具体用法请查询php相关文档。

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

以上就是php实现将文件批量压缩打包下载的全部内容,我们也还可以利用php调用linux系统的shell脚本来实现这个功能,这是一个思路,希望大家可以研究研究。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1065566.htmlTechArticlephp实现网站文件批量压缩下载功能, 利用php实现将文件批量压缩打包下载,这个过程中将使用到 ZipArchive 这个类,注意使用该类之前,li...
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