1

file_get_contents()にURLから画像を取得させ、それらをzipファイルとして出力させるにはどうすればよいですか。例えば

http://example.com/image1.jpg
http://example.com/image1.jpg
http://example.com/image1.jpg

file_get_contentsを使用して取得すると、文字列に格納されます。次に、この文字列を.zipに変換するにはどうすればよいですか。

ここで、画像のURLがエンコードされたjsonから抽出されていることを確認します。

4

2 に答える 2

0

これを試して

<?php

$files = array(
        'http://flask.pocoo.org/static/logo/flask.png',
        'http://flask.pocoo.org/static/logo/flask.pdf');

function create_zip(array $files, $destination='img.zip'){
    $zip = new ZipArchive();    
    $zip->open($destination, ZIPARCHIVE::CREATE);
    foreach($files as $file){
        print $file;
        if(copy($file, basename($file))){   
            print 'Successfully Copied ';
            if(file_exists(basename($file))){
                $zip->addFile(basename($file));
            }
        }else{
            print 'Failed to copy !!!';
        }
    }   
    $zip->close();
}

create_zip($files, 'testing.zip');
于 2013-02-06T10:45:51.537 に答える
0

あなたは試すことができます

copy('http://example.com/image1.jpg', '_tmp/image1.jpg')
copy('http://example.com/image2.jpg', '_tmp/image2.jpg')
...
zip( _tmp );
delete( _tmp );
于 2013-02-06T10:05:18.443 に答える