在 PHP 制作的文件夹文件索引中生成最后修改的文件日期
我正在使用 php 生成的文件夹内容的简化索引,但无法添加上次修改日期的显示。
他是我原来的工作代码:
<?php
foreach (glob("*.*") as $filename) {
echo "<a href='".$filename."'>".$filename."</a> - ".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> - ".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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定已设置
$last_modified
吗?您可能需要使用 filemtime() 来获取上次修改日期。结果代码:
Are you sure
$last_modified
is being set at all? You might want to use filemtime() to get the last modified date.Resulting code: