Zend save image from url

I retrieve all img urls from the array and get the image urls from external sites ...

How can I save these images?

I tried to use

$upload = new Zend_File_Transfer_Adapter_Http();
 $upload->setDestination("img/");

 # Returns the file name for 'doc_path' named file element
 $name = $upload->getFileName('http://zendguru.files.wordpress.com/2009/04/ajax-form1.jpg');

but I don’t get anything saved plus his statement Method call undefined: - Zend_File_Transfer_Adapter_Http::setOption()

+3
source share
2 answers

I think you cannot do this using Zend_File_Transfer_Adapter_Http, as this only works with downloaded files. However, you can use this Zend_Http_Client. For instance:

    $c = new Zend_Http_Client();
    $c->setUri('http://zendguru.files.wordpress.com/2009/04/ajax-form1.jpg');
    $result = $c->request('GET');        
    $img = imagecreatefromstring($result->getBody());
    imagejpeg($img,'img/test.jpg');
    imagedestroy($img);
+4
source

You should not use Zend for this. Normal PHP will do.

$ch = curl_init('http://zendguru.files.wordpress.com/2009/04/ajax-form1.jpg');
$fp = fopen('/img/flower.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
+1
source

All Articles