dean jase
dean jase

Reputation: 1161

zend saving image from url

i am extracting all img urls from an array and getting image urls from external sites...

how do i go about saving these images?

i tried using

$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 im getting nothing saved plus its saying Call to undefined method:- Zend_File_Transfer_Adapter_Http::setOption()

Upvotes: 3

Views: 2706

Answers (2)

Marcin
Marcin

Reputation: 238111

I think that you cannot do it using Zend_File_Transfer_Adapter_Http as this works only with uploaded files. However, you could use Zend_Http_Client for this. For example:

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

Upvotes: 4

Raj
Raj

Reputation: 22926

You should not use Zend for this. Plain PHP would 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);

Upvotes: 1

Related Questions