PHP 多个远程图片打包下载

不多比比。

<?php


$image1 = "http://mm_img.0-0-2.cn/Img/img/img_2018-07-27_1385_15326602381730.png";


$files = array($image1);

$tmpFile = tempnam('/tmp', '');

$zip = new ZipArchive;
$zip->open($tmpFile, ZipArchive::CREATE);
foreach ($files as $file) {
    // download file
    // $fileContent = file_get_contents($file);

    $ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 0); 
	curl_setopt($ch,CURLOPT_URL,$file); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	$fileContent = curl_exec($ch);
	curl_close($ch);

    $zip->addFromString(basename($file), $fileContent);
}
$zip->close();

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=file.zip');
header('Content-Length: ' . filesize($tmpFile));
readfile($tmpFile);

unlink($tmpFile);
 

?>

猜你喜欢

转载自blog.csdn.net/Mobius_z/article/details/81238592