<?php //获取参数 $file = $_GET['file'];//路径 我这里使用:号分割 例如在服务器当前文件夹下的 upload/user/20170306xgtlne.doc:upload/user/xxx.jpg $name=$_GET['name'];//下载文件名 //分隔符:放到$files数组 $files = explode(":", $file); //print_r($files); //function addFileToZip($path,$zip){ // $handler=opendir($path); //打开当前文件夹由$path指定。 // while(($filename=readdir($handler))!==false){ // if($filename != "." && $filename != ".."){//文件夹文件名字为'.'和‘..',不要对他们进行操作 //if(is_dir($path."/".$filename)){// 如果读取的某个对象是文件夹,则递归 //addFileToZip($path."/".$filename, $zip); //}else{ //将文件加入zip对象 //$zip->addFile($path."/".$filename); //} // } // } // @closedir($path); //} $zip=new ZipArchive();//创建一个zip //在本地生成rusume.zip,如果存在就覆盖 if($zip->open('rusume.zip', ZipArchive::OVERWRITE)=== TRUE){ for ($x=0; $x<sizeof($files)-1; $x++) { //第一个参数是文件位置,第二个参数是文件名字 取路径最后的名字 $zip->addFile($files[$x],preg_replace('/.*\//','',$files[$x])); } $zip->close(); //关闭处理的zip文件 } header('Content-type: application/zip'); header('Content-Disposition: attachment; filename='.$name.".zip"); readfile("rusume.zip"); ?>