The glob() function is used to get an array of filenames or directories. Then, array_multisort() function is sorting filenames according to the file’s created time. Lastly, it can be presented as intended with foreach looping.

$files = glob("/Path_to_Reports/*.csv");
// newer files come first by sorting as below
array_multisort(array_map('filemtime', $files), SORT_NUMERIC, SORT_DESC, $directory);
foreach ($files as $filename) {
  echo '<a href="' . $filename . '" >' . basename($filename) . '</a><br>';
}

Leave a Reply

Your email address will not be published. Required fields are marked *