Get list of files in a directory by date modified with PHP

 

If you need to go a directory with PHP and get changed on a specific date files, you can easily get to this feature I created a few days ago.


function getFilesFromDate($dir, $day=null){
 if ($day==null)
  $day = time();
   
 // Leo todos los ficheros de la carpeta
 $dir = opendir($dir);
 while ($file = readdir($dir)){
  if ($file!='.' && $file!='..' && is_file($dir.'/'.$file) && date("Ymd", $day)==date("Ymd", filemtime($dir.'/'.$file))){
   $arrfiles[] = $file;
  }
 }
 closedir($dir);
 return $arrfiles;
}

As we see, only you have to go through the directory and day. If we do not catch function on the current day to search.

Comments

Popular posts from this blog

Coronavirus symptoms: what are they and should I call the doctor?

6 Big Reasons to Learn Even a Little HTML & CSS

Ads