0

我正在使用 php 生成的文件夹内容的简化索引,但我无法添加最后修改日期的显示。

他是我原来的工作代码:

<?php
foreach (glob("*.*") as $filename) {
    echo "<a href='".$filename."'>".$filename."</a>&nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; ".intval(filesize($filename) / (1024 * 1024))."MB<br>"; 
}
?>

我想要的是为每个文件添加最后修改日期。

但是我得到了零日期(31-12-1969),这意味着我的代码无法识别它必须与索引的每个文件一起使用:

<?php
foreach (glob("*.*") as $filename) {
echo "Last modified " . date("l, dS F, Y @ h:ia", $last_modified);
    echo "<a href='".$filename."'>".$filename."</a>&nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; ".intval(filesize($filename) / (1024 * 1024))."MB<br>"; 
}
?>
</p> 

你知道我该如何解决吗?非常感谢你,如果你能帮忙:)

4

1 回答 1

1

Are you sure $last_modified is being set at all? You might want to use filemtime() to get the last modified date.

Resulting code:

<?php
foreach (glob("*.*") as $filename) {
echo "Last modified " . date("l, dS F, Y @ h:ia", filemtime($filename)) . '<br />';
    echo "<a href='".$filename."'>".$filename."</a>&nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; ".intval(filesize($filename) / (1024 * 1024))."MB<br>"; 
}
?>
于 2011-06-05T20:32:22.723 回答