0

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 :)

1 Answer 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>"; } ?> 
Sign up to request clarification or add additional context in comments.

2 Comments

EXCELLENT ! Thank you very much, I'm truly grateful ! :)
Just an FYI, if they answered the question correctly, you should give it an upvote and mark it as the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.