I started a few weeks ago to use php because i want to make a gallery for the pictures of my daughter.
I succeeded in creating a php gallery that do what i want except that the menu is giving me a little problem.
In fact my menu is reading the directories that are in my current directory and use these names to make the menu.
The name of my directories are like MM-YYYY but of course this is not sorting correctly.
It gives me something like this:
01-2006
02-2006
...
10-2005
11-2005
12-2005
And of course i want it to be the following:
...
10-2005
11-2005
12-2005
01-2006
02-2006
Some ppl will say to put the year at the first position followed by the months but as i am dutch we are used to place the months before the year.
Can someone tell me how i could sort my array containing all the directorynames to fit what i want?
This is the code without placing it in an array and it gives me the first result.
I tried several solutions by placing it in an array but then i don't know how to start to fix my problem.
Thanks in advance for any help.
Code: Select all
$dirname = ".";
$dh = opendir($dirname);
while ( gettype($file = readdir($dh)) != "boolean" )
{
if ( is_dir( "$dirname/$file" ) && ( $file != "." ) && ( $file != ".." ) )
{
print " <a href=\"cg_gallery1.php?dir=$file\">$file</a>\n <br/>\n";
}
}
closedir ($dh);PS: I need those directories because my gallery is using the name of the directory to read all the images in the directory to make my gallery.