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?
Check if the $file var is actually pointing to a correct file
foreach($dir as $file)
{
if(is_file($file))
{
$mod_date=date("F d Y H:i:s.", filemtime($file));
echo "<br>$file last modified on ". $mod_date;
}
else
{
echo "<br>$file is not a correct file";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With