Curl download image not working

Posted by mark on Stack Overflow See other posts from Stack Overflow or by mark
Published on 2010-12-23T09:50:26Z Indexed on 2010/12/23 9:54 UTC
Read the original article Hit count: 202

Filed under:

I would like to check whether a remote image is not older than 2 days and then download it. The image is not downloaded in anycase. What is wrong here?

  $ch = curl_init($file_source);  // the file we are downloading

curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_FILETIME, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_exec($ch); $headers = curl_getinfo($ch); $last_modified = $headers['filetime'];

if ($last_modified != -1) { if ($last_modified>time()-86400*2) { $ch2 = curl_init($file_source); $wh = fopen($file_target, 'wb') or errorIMG('003'); curl_setopt($ch2, CURLOPT_FILE, $wh);

  curl_setopt($ch2, CURLOPT_TIMEOUT, 25);

curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch2, CURLOPT_HEADER, true); curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);

curl_exec($ch2);
curl_close($ch2);
fclose($wh);

}

}

curl_close($ch);

© Stack Overflow or respective owner

Related posts about curl