Pages

Thursday, August 18, 2011

Image download using CURL - PHP

$url = 'IMAGE PATH URL';
  //$random_no = rand(10000,99999999);  // for random number
  //$file_handler = fopen($random_no.'.jpeg', 'w');  // random number image name
$file_handler = fopen('image1.jpeg', 'w');   // static image name as image1
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FILE, $file_handler);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_exec($curl);
curl_close($curl);
fclose($file_handler);

Using this code you can download image from server where 'IMAGE PATH URL' is the url of image. Image is generated in jpeg file extension named as image1 or you can use random generated name.

Hope its help you.

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete