话不多说 直接上代码
$filename = "img.zip"; // 压缩文件名
$zip=new \ZipArchive();
$zip->open($filename,\ZipArchive::CREATE); //创建一个压缩文件
// 往压缩文件里面填充文件 $path => 要压缩的文件路径 因为我是多个文件 所以是通过循环的方法是添加文件
for($i = 0; $i <= count($path); $i++){
$zip->addFile($path[$i],basename($path[$i]));
}
if($zip->close()){ // 释放内存
$file = "https://域名/web/img.zip"; // 这是生成后的压缩文件地址
header('Content-Type:text/html;charset=utf-8');
header('Content-disposition:attachment;filename=img.zip');
$filesize = filesize($file);
readfile($file);
header('Content-length:'.$filesize);
unlink($filename);
}