Saurdo Posted August 9, 2006 Share Posted August 9, 2006 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.phpThanks for your time! Link to comment https://forums.phpfreaks.com/topic/17067-need-help-sorting-this-gallery-alphabetically/ Share on other sites More sharing options...
poirot Posted August 9, 2006 Share Posted August 9, 2006 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(). Link to comment https://forums.phpfreaks.com/topic/17067-need-help-sorting-this-gallery-alphabetically/#findComment-72049 Share on other sites More sharing options...
micah1701 Posted August 9, 2006 Share Posted August 9, 2006 sort only works on arraysyou could use it like this:$imgfiles[] = $img;sort($imgfiles); Link to comment https://forums.phpfreaks.com/topic/17067-need-help-sorting-this-gallery-alphabetically/#findComment-72051 Share on other sites More sharing options...
Saurdo Posted August 9, 2006 Author Share Posted August 9, 2006 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] Link to comment https://forums.phpfreaks.com/topic/17067-need-help-sorting-this-gallery-alphabetically/#findComment-72079 Share on other sites More sharing options...
litebearer Posted August 9, 2006 Share Posted August 9, 2006 hmmm, this may be of some help.http://www.nstoia.com/toh/technical/listdir/index.phpIt lists a folder's contents and can sort by name, date or size - ascending or descending - and make them clickable linksLite... Link to comment https://forums.phpfreaks.com/topic/17067-need-help-sorting-this-gallery-alphabetically/#findComment-72084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.