Curl download image not working
- by mark
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_modifiedtime()-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);