I have an image gallery that doesn’t have any sorting options. What I want to do is for the gallery to sort by date (newest to oldest) by directory, not by file. I tried everything possible to modify the script, but unsuccessfully. Can someone help me look into the following script and see what needs to be modified:
[code=php]function getListing($wd, $type = “dirs”)
{
$dir->path = $wd;
$dir->files = array();
$dir->dirs = array();
$dp = opendir($dir->path);
if(!$dp) return false;
switch($type) {
case “images” :
while(false !== ($entry = readdir($dp)))
if(preg_match(“/(jpeg|jpg|jpe|png|gif|bmp|tif|tiff)$/i”,$entry))
$dir->files[] = $entry;
sort($dir->files);
rewinddir($dp);
//run on and get dirs too
case “dirs” :
while(false !== ($entry = readdir($dp)))
if(
is_dir($wd.$entry) &&
$entry != “.” &&
$entry != “..”
) $dir->dirs[] = $entry;
sort($dir->dirs);
break;
case “all” :
while(false !== ($entry = readdir($dp)))
if(is_dir($wd.$entry)) $dir->dirs[] = $entry;
else $dir->files[] = $entry;
sort($dir->dirs);
sort($dir->files);
break;
default :
while(false !== ($entry = readdir($dp)))
if(strpos(strtolower($entry),$type))
$dir->files[] = $entry;
sort($dir->files);
}
closedir($dp);
return $dir;
}
Thanks in advanced!