在PHP中显示最后修改的日期


Displaying last modified date in PHP

我有一个关于一段PHP代码的问题。

我使用这段代码来打印"upload"文件夹的内容。每个文件都有自己的<div>,打印的文本有点像这样:文件名+扩展名。

    <?php
$dir   = "upload/"; // the directory that is being checked
$exclude = array(".", "..");
$files = scandir($dir);
$files = array_diff($files, $exclude);
if(!empty($files)) // check if the files array is not empty
{
    foreach ($files as $file) // print every file in the files array
        print "
<div class='fileicon'>
<div id='hint'>
<a href='upload/$file' style='text-decoration: none;' download>
<p class='filetext'>$file</p>
</a>
</div>
</div>";
}
else 
{
    echo "There are no files in directory"; // print error message if there are no files
}
?>
我的问题是……有没有什么方法可以让我显示上次修改打印文件的日期?

我想使用filemtime,但我不知道如何在当前上下文中使用它

foreach ($files as $file){
  echo date ("F d Y H:i:s", filemtime($file));
}

它有助于阅读手册,特别是示例。到目前为止你尝试了什么?