Tom*_*igh 41
您可以使用curl_getinfo()
以下方法执行以下操作:
<?php
$curl = curl_init('http://www.example.com/filename.txt');
//don't fetch the actual page, you only want headers
curl_setopt($curl, CURLOPT_NOBODY, 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);
if ($result === false) {
die (curl_error($curl));
}
$timestamp = curl_getinfo($curl, CURLINFO_FILETIME);
if ($timestamp != -1) { //otherwise unknown
echo date("Y-m-d H:i:s", $timestamp); //etc
}
Run Code Online (Sandbox Code Playgroud)
小智 23
在PHP中,您可以使用本机函数get_headers()
:
<?php
$h = get_headers($url, 1);
$dt = NULL;
if (!($h || strstr($h[0], '200') === FALSE)) {
$dt = new \DateTime($h['Last-Modified']);//php 5.3
}
Run Code Online (Sandbox Code Playgroud)
Dan*_*tti 13
来自php的文章:
<?php
// outputs e.g. somefile.txt was last modified: December 29 2002 22:16:23.
$filename = 'somefile.txt';
if (file_exists($filename)) {
echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>
Run Code Online (Sandbox Code Playgroud)
filemtime()是这里的关键.但我不确定您是否可以获取远程文件的最后修改日期,因为服务器应该将其发送给您...也许在HTTP标头中?