$filename = date ( 'YmdH' ) . ".zip";
// 生成文件 $zip = new \ZipArchive (); // 使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释 if ($zip->open ($filename ,\ZipArchive::OVERWRITE) !== true) { //OVERWRITE 参数会覆写压缩包的文件 文件必须已经存在 if($zip->open ($filename ,\ZipArchive::CREATE) !== true){ // 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip exit ( '无法打开文件,或者文件创建失败' ); } }foreach ($imageData as $key =>$file) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch,CURLOPT_URL,$file); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $fileContent = curl_exec($ch); curl_close($ch); $info = pathinfo($file); $zip->addFromString(basename($key.'.'.$info['extension']), $fileContent); } $zip->close(); //var_dump($filename); if(file_exists($filename)){ ob_end_clean(); header('Content-Description: File Download'); header('Content-type: application.octet-stream'); header('Content-Disposition: attachment; filename='.basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($filename)); readfile($filename); exit; }