Jump to content

Need help sorting this gallery alphabetically!


Saurdo

Recommended Posts

Good evening comrades! I am currently setting up a photo gallery and all is running smoothly. However, I'm having some trouble organizing my photographs and folders alphabetically. The script reads from a directory I define and displays the images and folders that are in the directories.

Here's the script:

[code=php:0]
function showDirs() {

global $gallery_root, $currentdir, $file, $excluded_folders;
$runonce = false;
if ($dir_content = opendir($gallery_root.$currentdir)) {

while ( false !== ($dir = readdir($dir_content)) ) {
if (is_dir($gallery_root.$currentdir.$dir) && !in_array($dir, $excluded_folders) && $dir!='.' && $dir!='..' ) {
if ( !$runonce ){
echo '<div class="folder">Folders:<br/><table class="foldersbox">';
$runonce = true;
}
echo '<tr><td><a href="'.$_SERVER['PHP_SELF'].'?file='.$currentdir.$dir.'/"><img src=http://www.saurdo.com/images/folder.gif> '.$dir.'</a></td></tr>';
}
}
}
if ( $runonce )
echo '</table></div><br/>';
}
[/code]

I've tried sort($dir); , sort($dir_content); , sort($currentdir.$dir); , natcasesort($dir); , and so on and so forth. None of them have worked. I'm placing it right after the loops as I've learned through example from another script. My knowledge of PHP is limited so can someone please explain to me the correct way to go about this and what I'm doing wrong?

Another not so related thing is displaying the time/date that a file was uploaded. I've seen another script that can do this but instead of enlightening me it confused me. If someone could show me how to do this as well then you'd save me a lot of time and trouble.

My Gallery is located here: http://www.saurdo.com/gallery.php

Thanks for your time!
Where are you trying to insert that?

From what I see, it will display the images as it retrieves them from the folder contents.
You cannot use sort() because there is no array to sort.

If you are planning to use sort you store them (the images) in an array and THEN use sort().
Alright, so i have to store them in array. So where do I insert the array?

Would this work?

[code=php:0]
function showDirs() {

global $gallery_root, $currentdir, $file, $excluded_folders;
$runonce = false;
if ($dir_content = opendir($gallery_root.$currentdir)) {

while ( false !== ($dir = readdir($dir_content)) )
$dirs[] = $dir;
sort($dirs);
{
if (is_dir($gallery_root.$currentdir.$dir) && !in_array($dir, $excluded_folders) && $dir!='.' && $dir!='..' ) {
if ( !$runonce ){
echo '<div class="folder">Folders:<br/><table class="foldersbox">';
$runonce = true;
}
echo '<tr><td><a href="'.$_SERVER['PHP_SELF'].'?file='.$currentdir.$dir.'/"><img src=http://www.saurdo.com/images/folder.gif> '.$dirs.'</a></td></tr>';
}
}
}
if ( $runonce )
echo '</table></div><br/>';
}[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.