我正在尝试将图像 url 写入一个数组,该数组将写入一个 zip 并强制下载
当我编写以下数组时
$images= array(
'http://distilleryimage10.s3.amazonaws.com/de532c02488c11e2b62722000a1fbc10_7.jpg',
'http://distilleryimage10.s3.amazonaws.com/8b9b59e848fb11e2b39e22000a9d0df1_7.jpg'
);
连同此问题底部的大脚本一起,zip 下载正常。
但是当我使用以下
foreach ($response['data'] as $data) {
$images[] = $data['images']['standard_resolution']['url'];
}
zip 下载但有一个弹出窗口说 zip 无效。创建数组的 foreach 只写入 url。
下载压缩包的代码
# create new zip opbject
$zip = new ZipArchive();
# create a temp file & open it
$tmp_file = tempnam('.','');
$zip->open($tmp_file, ZipArchive::CREATE);
# loop through each file
foreach($images as $image){
# download file
$download_file = file_get_contents($image);
#add it to the zip
$zip->addFromString(basename($image),$download_file);
}
# close zip
$zip->close();
# send the file to the browser as a download
header('Content-disposition: attachment; filename=download.zip');
header('Content-type: application/zip');
readfile($tmp_file);
如果有人可以提供帮助,我将不胜感激,因为我对此非常困惑