如何在 php 中找到文件的最后访问时间

How do I find the last access time of a file in php

我需要知道上次使用 PHP 访问文件 (main.html) 的时间。我希望用户能够看到其他用户最后一次访问该页面的时间。 我如何使用 PHP 来做到这一点?

函数fileatime用于获取给定文件的最后访问时间。

$filename = 'somefile.txt';
    if (file_exists($filename)) {
        echo "$filename was last accessed: " . date("F d Y H:i:s.", fileatime($filename));
    }

// outputs e.g.  somefile.txt was last accessed: December 29 2002 22:16:23.