Jump to content


Photo

Need help sorting this gallery alphabetically!


  • Please log in to reply
4 replies to this topic

#1 Saurdo

Saurdo
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationCalifornia

Posted 09 August 2006 - 09:16 PM

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:

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/>';
}

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!

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 09 August 2006 - 09:23 PM

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().
~ D Kuang

#3 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 09 August 2006 - 09:25 PM

sort only works on arrays

you could use it like this:

$imgfiles[] = $img;
sort($imgfiles);

"Confidence in the face of risk."

#4 Saurdo

Saurdo
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationCalifornia

Posted 09 August 2006 - 10:03 PM

Alright, so i have to store them in array. So where do I insert the array?

Would this work?

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/>';
}


#5 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 09 August 2006 - 10:09 PM

hmmm, this may be of some help.

http://www.nstoia.co...stdir/index.php

It lists a folder's contents and can sort by name, date or size - ascending or descending - and make them clickable links

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users