在 PHP 制作的文件夹文件索引中生成最后修改的文件日期

发布于 2024-11-12 20:06:54 字数 798 浏览 3 评论 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>"; 
}
?>

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

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

<?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> 

您知道我如何修复它吗?如果您能提供帮助,非常感谢:)

I'm using a php-generated simplified index of the contents of a folder, but I fail at adding the display of the last modified date.

He's my original working code :

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

What I want is to add the last modified date for each file.

But I get the zero-date (31-12-1969), meaning my code FAILS at recognizing it has to work with each file of the index :

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

Would you know how I could fix it ? Thank you VERY MUCH if you can help :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

誰ツ都不明白 2024-11-19 20:06:54

您确定已设置 $last_modified 吗?您可能需要使用 filemtime() 来获取上次修改日期。

结果代码:

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

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>      -     ".intval(filesize($filename) / (1024 * 1024))."MB<br>"; 
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文