I'm trying to sort the content of a folder by their date/time. my code bellow gets all the content properly but they are all over the place and they are not sorted by date/time.
my code:
if(isset($_GET['dir'])) {
$directory = $_GET['dir'];
$dir = "".$directory."";
$files = scandir($dir);
//rsort($files);
$TIMEANDATE = date("F d Y h:i A");
foreach ($files as $file) {
$date = filemtime(''.$dir.'/'.$file.'');
if ($file != '.' && $file != '..') {
array_multisort(array_map('filemtime', $file), SORT_ASC, $file);
$filesize = human_filesize(filesize(''.$dir.'/'.$file.''));
$all_doc .= "<tr>
<td><input type='checkbox'/></td>
<td>".$fileExt." <a class='defaults' href='" . $dir ."/". $file . "'>". $file ."</a> <a href=''><i title='Move' class='fa fa-refresh'></i></a>
<a href='folder.php?del=" . $dir ."/". $file . "'><i title='Delete' class='fa fa-times'></i></a>
</td>
<td>Status</td>
<td>".date('F d Y h:i A', $date)."</td>
<td>".$filesize."</td>
</td>
</tr>";
$i++;
}
}
}
I tried this line of code but it doesn't sort them:
array_multisort(array_map('filemtime', $file), SORT_ASC, $file);
could someone please advise on this?
any help would be appreciated.
Edit: this question has no answer in other posts because the code is clearly different and I cannot change my code to reflect other people's codes on other posts. so I need to work with my own code.