/    Sign up×
Community /Pin to ProfileBookmark

Order by Date

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;
}[/code]

Thanks in advanced!

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @dp78 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...