Getting last modification date of files in directory using PHP

后端 未结 3 443
走了就别回头了
走了就别回头了 2020-12-20 14:04

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          


        
相关标签:
3条回答
  • 2020-12-20 14:19

    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))

    0 讨论(0)
  • 2020-12-20 14:23

    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";
      }
    }
    
    0 讨论(0)
  • 2020-12-20 14:28

    date("F d Y H:i:s.", false) is what you are getting. see documentation of filemtime. It returns false on failure.

    0 讨论(0)
提交回复
热议问题