[0] => E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\aa.pdf [1] => E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\bb.pdf [2] => E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\cc.pdf [3] => E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\dd.pdf [4] => E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\ee.pdf [5] => E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\ff.pdf [6] => E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\gg.pdf

逻辑:先把文件压缩到指定目录(自定义$addonFile目录下),然后再把文件输出下载

代码如下:

$files = ('E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\aa.pdf','E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\bb.pdf','E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\cc.pdf','E:\phpstudy_pro\WWW\subject\public\uploads\file\tiantan\2022\dd.pdf');
// 压缩文件名
$addonFile = ROOT_PATH.'public'.DS.'uploads'.DS.'downzip'.DS.'学科评估_【'.$info['hospital'].'_'.$this->year. '年】.zip';
$zip = new \ZipArchive;
//新建zip压缩包
$zip->open($addonFile,\ZipArchive::CREATE | \ZipArchive::OVERWRITE);
//把文件一张一张加进去压缩
foreach ($files as $key => $value) {
    $zip->addFile($value,basename($value));
//打包zip
$zip->close();
header("Cache-Control: public"); 
header("Content-Description: File Transfer"); 
header('Content-disposition: attachment; filename='.basename($addonFile)); //文件名 
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($addonFile)); //告诉浏览器,文件大小 
readfile($addonFile);