PHP code to check if a file is over 5 minutes old

Today I had a need to check the modification date of a file, and see if it was more than 5 minutes old. Here is the code I wrote for this:

(Update: I got a comment from my good friend Patrick Nelson with code to do this in fewer lines, shown below)

$file_time = filemtime("some_file_path.txt");
$expires = strtotime("-5 minutes");
if ($file_time < $expires){
   // do something
}
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Twitter

Leave a Reply