我正在尝试将图片网址写入一个将写入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。
下载zip包的代码
# 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);
如果有人能帮助我,我会很感激,因为我很难坚持这个
答案 0 :(得分:0)
阵列不是我的事,但我认为:
# loop through each file
foreach($images as $key=>$value){
# download file
$download_file = file_get_contents($value);
#add it to the zip
$zip->addFromString(basename($value),$download_file);
}