php批量下載圖片



//批量下載圖片
public function download_img_all(){

//圖片數組
$res = array(
[0] = array(
'ima_path'=>'/Uploads/1.png',
),
[1] = array(
'ima_path'=>'/Uploads/2.png',
)

);
//創建壓縮包的路徑
$filename = $_SERVER['DOCUMENT_ROOT'].'/Uploads/Dwonload.zip';

$zip = new \ZipArchive;

$zip->open($filename,$zip::CREATE);
//往壓縮包內添加目錄
$zip->addEmptyDir('images');

foreach ($res as $value) {
$fileData = file_get_contents( $_SERVER['DOCUMENT_ROOT'].$value['img_path']);
if ($fileData) {
$add = $zip->addFromString('images/'.$value['img_path'].'.jpg', $fileData);
}
}

$zip->close();
//打開文件


//下載文件
ob_end_clean();
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename='.time().'.zip');
header('Content-Length: '.filesize($filename));
error_reporting(0);
readfile($filename);
flush();
ob_flush();


}
download_img_all();
//大概就是這樣子

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM