如何在PHP中获得正确的最后访问文件?我试过fileatime,但它返回几天最后访问时间戳,但我确信有很多文件访问更多以后。filetime如何获取时间戳,什么是"访问"?GIT应该制造一些麻烦吗?(结帐是否作为文件的"访问"?…)
有两点需要注意
-
fileatime函数的结果被缓存。使用clearstatcache()来
-
一些Unix系统禁用了访问时间更新,因为这函数会降低应用程序的性能
那么,试试下面的例子
<?php
clearstatcache();
echo fileatime("test.txt");
echo "<br />";
echo "Last access: ".date("F d Y H:i:s.",fileatime("test.txt"));
?>
$filename = 'somefile.txt';
if (file_exists($filename)) {
echo "$filename was last accessed: " . date("F d Y H:i:s.", fileatime($filename));
}
请参考此http://php.net/manual/en/function.stat.php
我不知道它是否适用于文件,但我把它用于文件夹。
$stat = stat('path_of_dir_or_file');
$timespan= $stat['atime']; // will show unix time stamp.
$time=date('d/m/Y', $timespan);