Jump to content

[SOLVED] Trouble alphabetizing directory list


ScopeXL

Recommended Posts

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 );
      }
      ?>

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.