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 :)
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>";
}
?>
精彩评论