编程语言
首页 > 编程语言> > php 批量下载远程图片并压缩

php 批量下载远程图片并压缩

作者:互联网

$urlArr=['https://files.dianlinet.com/uploads/images/img/202101/08/cy_1610083365_1agwoAwBXl.jpg','https://files.dianlinet.com/uploads/images/img/202101/08/cy_1610083365_1agwoAwBXl.jpg'];
$temp=tempnam('/tmp','');
$zip = new \ZipArchive;
if ($zip->open($temp, \ZIPARCHIVE::CREATE)!==TRUE) {
return $this->failed('无法打开文件,或者文件创建失败',400);
}
foreach ($urlArr as $value){
$zip->addFromString(basename($value),file_get_contents($value));
}
$zip->close();
header('Content-disposition: attachment; filename='.basename("downs.zip")); //文件名
header("Content-Type: application/zip"); //zip格式的
header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
header('Content-Length: '. filesize($temp)); //告诉浏览器,文件大小
@readfile($temp);
unlink($temp);

 

标签:zip,temp,批量,basename,value,Content,header,php,远程
来源: https://www.cnblogs.com/mrxiangqian/p/14781547.html