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.
<?php date_default_timezone_set('Europe/Berlin'); if(intval(date("d", time() - filemtime('get_external_ip.php'))) > 1) echo "old\n"; else echo "new\n";
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.