之前寫過一篇【 Xoops做一個php下載多檔打包壓縮成ZIP格式方法 】工作心得,不過那方法在PHP8.0中無法使用,原因是new ZipArchive必須要先有實體的zip檔才能實體化,否則會出現 ValueError: ZipArchive::open(): Argument #1 ($filename) cannot be empty 錯誤訊息,必須修改new ZipArchive寫法在$zip->open之前就先建立一個暫存的zip檔,這樣後面的程式就沒問題了,修改方法如下 ※原本的new ZipArchive code function zipArchivefunction($url="",$zipname="",$temp="){ //$url 檔案原始路徑+檔名(陣列格式) //$zipname zip檔案名稱 //$temp 檔案暫存路徑+檔名 $zip = new ZipArchive; $zip->open($temp, ZipArchive::CREATE); //$url檔案路徑迴圈加入zip中 foreach ($url as $file) { $new_filename = substr($file, strrpos($file, '/') + 1); //重新定義壓縮檔路徑 $zip->addFile($file, $new_filename); } $zip->close(); /********使用header命令php下載zip檔************/ header('Content-Type: application/zip'); //指定類型 header("Content-type: ".filetype("$temp")); //指定下載時的檔名 header("Content-Disposition: attachment; filename=".$zipname.""); //輸出下載的內容。 readfile($temp); unlink($temp); //刪除暫存檔 } ※ php8.0修改過後的new Z...