Get the age of a file with PHP

If you work with the filesystem and PHP you may get to a point where you have to find out the file age. PHP offers a function that you can use for that. This function is filemtime.

Get the file age

The filemtime function needs a string with the filename or a full path with the filename as param. The result is the age of that file, which can be formatted to a more readable format with the date function.

This script finds out if the file is older than one day. If so, it prints out ‘old’ or ‘new’ if the file is only some hours old.

(Visited 658 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *