我想获取远程文件的最后修改时间。我正在使用我在stackoverflow上找到的这段代码
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
//don't fetch the actual page, you only want headers
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_HEADER, true);
//stop it from outputting stuff to stdout
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// attempt to retrieve the modification date
curl_setopt($curl, CURLOPT_FILETIME, true);
$result = curl_exec($curl);
echo $result;
$info = curl_getinfo($curl);
print_r($info);
if ($info['filetime'] != -1) { //otherwise unknown
echo date("Y-m-d H:i:s", $info['filetime']); //etc
}
这段代码有问题,我一直在得到 filetime = -1。但是当我删除
curl_setopt($curl, CURLOPT_NOBODY, true);
然后我得到正确的修改时间。
是否有可能获得最后修改时间,但
curl_setopt($curl, CURLOPT_NOBODY, true);
包含在脚本中。我只需要页面的标题,而不是正文。
提前致谢