Sunday, 16 September 2012

Saving An Image Retrieved Via cURL


How can save images without use of browser with the help of Curl.
Some time we need save url image help of code without open browser
This function save image without open link.
$url="http://google.com/imagename.jpg";                                                                          
$ch = curl_init($url);
$fp = fopen(‘folderpath/card1.jpg', 'wb');// folder path where you save image
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

Note : One of the main reasons to use cURL to save or display a remote image is that some servers/hosts have allow_url_fopen turned off. This means functions like fopen can’t open files held on external servers.
I hope you have enjoyed this tutorial

No comments:

Post a Comment