Gwolf Wolfy Gwolf Wolfy - 10 months ago 72
PHP Question

CURL download image php not working

I'm trying to download a dynamic generated image to my server using curl and php and for some reason I keep failing
Can someone help out...
Below is my code

function download_image($image_url){
$ch = curl_init($image_url);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // enable if you want
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1000); // some large value to allow curl to run for a long time
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_WRITEFUNCTION, "curl_callback");
curl_setopt($ch, CURLOPT_VERBOSE, true); // Enable this line to see debug prints

curl_close($ch); // closing curl handle

/** callback function for curl */
function curl_callback($ch, $bytes){
global $fp;
$len = fwrite($fp, $bytes);
// if you want, you can use any progress printing here
return $len;

$image_file = "ram.png";
$fp = fopen ($image_file, 'w+'); // open file handle


Maybe for this url using htmlspecialchars_decode will help when using the & in the url.

$url = htmlspecialchars_decode(",FFFF00|FF0000&chd=t:30&chf=bg,s,232526");