Getting last modification date of files in directory using PHP

Viewed 27262

I am trying to get the last modification date of all files in a directory using PHP.

I am using this:

foreach($dir as $file) 
{
$mod_date=date("F d Y H:i:s.", filemtime($file));
}

foreach($dir as $file) is returning the correct files, but all of the modification dates are coming back as 0000-00-00 00:00:00, instead of the actual modification date.

What changes do I need to make to get this working?

3 Answers

Rather than use glob function, why not use scandir function. Secondly, you could easily get the date format you want by using date("Y-m-d H:i:s", filemtime($file))

Related