0

Zipに書き込み、ダウンロードを強制する配列に画像のURLを書き込もうとしています

次の配列を書くと

$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);

私はこれにひどく立ち往生しているので、誰かが助けてくれればありがたいです

4

1 に答える 1

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);   
}
于 2012-12-18T14:39:23.657 に答える