easy display of last modified time for files using PHP

Not so much use for any websites I’ve built so far, but this will be useful for download pages to enable them to display the date of the current build or builds etc.

This script outputs the date and time that a file was last modified. You can format it any way you want.

$last_modified = filemtime("MY_FILE.txt"); // Insert your file name here
echo "Last modified " . date("l, dS F, Y @ h:ia", $last_modified); 
// eg. Last modified Tuesday, 30th March, 2010 @ 04:23pm

By using this with any file download, you can have your pages automatically update when you replace the downloadable files with alternate versions. Just make sure the file name is still the same.

About Cameron
I'm a final year Computer Science/Information Systems major. Already finished my BA in Politics/Philosophy. I do web and software freelance on the side, while I finish studying. Hoping to be self-employed by the end of my degree, otherwise off into the real-world I go....

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: