<?php $fileList = array( '/var/www/pics/001.jpg', '/var/www/pics/002.jpg', '/var/www/pics/003.jpg', '/var/www/pics/004.jpg', '/var/www/pics/005.jpg', '/var/www/pics/006.jpg', ); /*建立臨時壓縮檔*/ $file = tempnam("tmp", "zip"); $zip = new ZipArchive; $res = $zip->open($file, ZipArchive::CREATE|ZipArchive::OVERWRITE); if ($res!==true) { exit('壓縮錯誤');} foreach ($filePathList as $filePath){ $zip->addFile($filePath, $fileName); } $zip->close(); ob_end_clean(); header('Content-type: application/octet-stream'); header('Content-Transfer-Encoding: Binary'); header('Content-disposition: attachment; filename=pics_list.zip'); readfile($file); unlink($file); exit;
參考連結:PHP: ZipArchive - Manual
沒有留言:
張貼留言
你好!歡迎你在我的 Blog 上留下你寶貴的意見。