Php Curl仅在不超过2天的情况下下载图像
我只想从远程服务器下载一个不超过两天的映像 我下面运行的代码正确吗?我想知道下载前上次修改的Php Curl仅在不超过2天的情况下下载图像,php,curl,Php,Curl,我只想从远程服务器下载一个不超过两天的映像 我下面运行的代码正确吗?我想知道下载前上次修改的数据 $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
数据
$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);
$file\u source=>http://www.google.com/images/nav_logo29.png';
$ch=curl\u init($file\u source);
curl_setopt($ch,CURLOPT_超时,20);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_FILETIME,true);
curl_setopt($ch,CURLOPT_头,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,false);
$file_source = 'http://www.google.com/images/nav_logo29.png';
$ch = curl_init($file_source);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FILETIME, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); <-- don't download first
curl_exec($ch);
$headers = curl_getinfo($ch);
$last_modified = $headers['filetime'];
if ($last_modified != -1)
{
if ($last_modified>time()-86400*2) <-- not older than 2 days
{
$ch2 = curl_init($file_source);
$wh = fopen('YOUR_PATH, 'w');
curl_setopt($ch2, CURLOPT_FILE, $wh);
curl_exec($ch2);
curl_close($ch2);
fclose($wh);
}
}
curl_close($ch);