1

How can I cause file_get_contents() to get images from url and output them as a zip file. e.g

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

When retrieve with file_get_contents it'll store in a string, Now how can I convert this string into .zip.

it is to be cleared here that Images urls are being extracted from encoded json.

4

2 回答 2

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 回答
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 回答