Ai putea inlocui
$dir_handle = @opendir($path) or die("Unable to open folder");
while (false !== ($file = readdir($dir_handle)))
{
if($file == "index.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;
echo "<input type='CHECKBOX' name='file[]' value='$file'>";
echo "<a href='upload/$file' target='_blank'>";
echo "<img src='upload/$file' alt='$file' style='height: 100px; width: 100px;'/></a> ";
}
closedir($dir_handle);
Cu
function sortByTime($a, $b) {
$datePuzzleA = explode("-", explode("_", $a)[0]);
$dateA = strtotime(implode("-", array_slice($datePuzzleA, 0, 3))." ".implode(":", array_slice($datePuzzleA, 3, 3)));
$datePuzzleB = explode("-", explode("_", $b)[0]);
$dateB = strtotime(implode("-", array_slice($datePuzzleB, 0, 3))." ".implode(":", array_slice($datePuzzleB, 3, 3)));
if ($a === $b) {
return 0;
}
return $b > $a ? -1 : 1;
}
$files = array_diff(scandir($path), array('.', '..', 'index.php'));
usort($files, "sortByTime");
foreach($files as $file) {
echo "<input type='CHECKBOX' name='file[]' value='$file'>";
echo "<a href='upload/$file' target='_blank'>";
echo "<img src='upload/$file' alt='$file' style='height: 100px; width: 100px;'/></a> ";
}
Desi nu cred ca e cea mai eleganta solutie.