PHP实现将文件打包成zip并下载

open($filename, ZipArchive::CREATE)==TRUE) {
  foreach( $datalist as $val){
   if(file_exists($val)){
    $zip->addFile( $val, basename($val));
   }
  }
  $zip->close();
 }
}
if(!file_exists($filename)){
 exit("无法找到文件");
}
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.basename($filename)); //文件名
header("Content-Type: application/zip"); //zip格式的
header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
header('Content-Length: '. filesize($filename)); //告诉浏览器,文件大小*/
header("Location:".$filename); 

你可能感兴趣的:(PHP实现将文件打包成zip并下载)