开发者

Generating last modified file dates in a PHP-made folder files index

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>&nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; ".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>&nbsp; &nbsp; &nbsp; - &nbsp; &nbsp; ".intval(filesize($filename) / (1024 * 1024))."MB<br>"; 
}
?>
</p> 

Would you know how I could fix it ? Thank you VERY MUCH if you can开发者_运维技巧 help :)


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>"; 
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜