Curl download image only if not older than 2 days
- by mark
I want to download a image from a remote server only if it is not older than 2 days.
I have the constructing as below now. Is this right? I want to now the last_modified data first before downloading.
$ch = curl_init($file_source); // the file we are downloading
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FILE, $wh);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FILETIME, true);
curl_exec($ch);
$headers = curl_getinfo($ch);
$last_modified = $headers['filetime'];
if ($last_modified != -1) { // unknown
echo date("Y-m-d", $last_modified); //etc
}
curl_close($ch);
fclose($wh);