Solution: In following example we have filtered files which are modified on current date (today’s date):
$source= "C:\wamp\www\Files\"; $files = scandir($source); $archiveFiles = array(); foreach($files as $file) { if (!in_array($file,array(".",".."))) { $lastModified = date('d/m/y',filemtime($source . '/' .$file)); IF($lastModified==date("d/m/y")) { array_push($archiveFiles, $file); } } }
$source contains the path of folder that contains files.
date(‘d/m/y’,filemtime($source . ‘/’ .$file)); Get modified date of files. We can change the format of date too for e.g. date(‘d-m-y’,filemtime($source . ‘/’ .$file));. You can also get timestamp value. Using timestamp you can filter the files according to time also.
IF($lastModified==date(“d/m/y”)) This will compare the last modified date with today’s date.
$archiveFiles array contains the filtered file names.