Reputation: 1161
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
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
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