ScopeXL Posted January 7, 2009 Share Posted January 7, 2009 Hello, I am new to PHP Freaks and this looks like a great place to seek help. I currently have a script that lists the folders from a directory in FTP (viewable at: http://webbot.bnetweb.org) I would like to order that list alphabetically by the column UserID (the UserID listed is the folder name). My current code only displays the folders retrieved in the order it gets them, not alphabetically. Can someone please tell me how to go about alphabetizing this list by the folder name or edit my code so it may do so? This will be much appreciated, thank you. <?php // Your start directory getDirectory('.'); function getDirectory( $path = '.', $level = 0 ) { // Directories to ignore when listing output. $ignore = array( '.', '..', 'images', 'icons', 'cgi-bin', '_private', '_vti_bin', '_vti_cnf', '_vti_log', '_vti_pvt', '_vti_txt' ); // Open the directory to the handle $dh $dh = @opendir( $path ); // Loop through the directory while( false !== ( $file = readdir( $dh ) ) ) { // Check that this file is not to be ignored if( !in_array( $file, $ignore ) ) { // Indent spacing for better view $spaces = str_repeat( ' ', ( $level * 5 ) ); // Show directories only if(is_dir( "$path/$file" ) ) { // Re-call this same function but on a new directory. // this is what makes function recursive. echo "$spaces<tr><td><a href='$path/$file/'>$file</a></td><td><iframe SRC='$path/$file/cc.php' WIDTH=220 HEIGHT=20 FRAMEBORDER=0 SCROLLING=NO></iframe></td><td><iframe SRC='$path/$file/onserver.php' WIDTH=220 HEIGHT=20 FRAMEBORDER=0 SCROLLING=NO></iframe></td></tr>"; getDirectory( "$path/$file", ($level+1) ); } } } // Close the directory handle closedir( $dh ); } ?> Link to comment https://forums.phpfreaks.com/topic/139773-solved-trouble-alphabetizing-directory-list/ Share on other sites More sharing options...
julia k Posted January 7, 2009 Share Posted January 7, 2009 Hi there! Instead of printing the results right away, why not storing them in an array? You can then sort it and print it. Link to comment https://forums.phpfreaks.com/topic/139773-solved-trouble-alphabetizing-directory-list/#findComment-731264 Share on other sites More sharing options...
ScopeXL Posted January 7, 2009 Author Share Posted January 7, 2009 I'm not quite sure how to place them in an array, I'm fairly new to PHP programming and am still figuring out a bunch of new things. If you would be kind enough to show me or give me an example that would be fantastic. Link to comment https://forums.phpfreaks.com/topic/139773-solved-trouble-alphabetizing-directory-list/#findComment-731265 Share on other sites More sharing options...
julia k Posted January 7, 2009 Share Posted January 7, 2009 I followed the link from your first post and it seems that you have sorted it out? Link to comment https://forums.phpfreaks.com/topic/139773-solved-trouble-alphabetizing-directory-list/#findComment-731629 Share on other sites More sharing options...
ScopeXL Posted January 7, 2009 Author Share Posted January 7, 2009 yes, thank you Link to comment https://forums.phpfreaks.com/topic/139773-solved-trouble-alphabetizing-directory-list/#findComment-731950 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.