Spaces:
Running
Running
File size: 767 Bytes
6420441 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php
function getImages($directory, $imageOrder = 'desc') {
$allowedTypes = array('jpg', 'jpeg', 'png', 'gif');
$files = array();
if (is_dir($directory)) {
$dirContent = scandir($directory);
foreach ($dirContent as $file) {
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (in_array($extension, $allowedTypes)) {
$files[] = $file;
}
}
// Use strtolower for case-insensitive comparison
$order = strtolower($imageOrder); // Normalize the input
if ($order == 'desc') {
rsort($files);
} elseif ($order == 'asc') {
sort($files);
} // Add other sorting options if needed
}
return $files;
}
?> |