Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    204
    Thanks
    29
    Thanked 0 Times in 0 Posts

    How do I make is display ASC

    I have this script that displays folder content,
    How do I make is display ASC, at the moment there is no order.


    PHP Code:
    <?
    /**
    * Change the path to your folder.
    * This must be the full path from the root of your
    * web space. If you're not sure what it is, ask your host.
    *
    * Name this file index.php and place in the directory.
    */
        // Define the full path to your folder from root
        
    $path "/home/xxxx/public_html/Links";

        
    // Open the folder
        
    $dir_handle = @opendir($path) or die("Unable to open $path");

        
    // Loop through the files
        
    while ($file readdir($dir_handle)) {

        if(
    $file == "." || $file == ".." || $file == "index.php" )

            continue;
            echo 
    "<a href=\"XXXXXX/Links/$file\" target=\"_blank\">$file</a><br />";

        }
        
    // Close
        
    closedir($dir_handle);
    ?>
    Last edited by Feckie; 01-30-2012 at 07:22 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Use a glob instead of opendir/readdir. I'm quite sure that one sorts by default.
    Glob will return an array as well, so you may want to capture it completely so you can use a sort on the array itself prior to iterating. This would work for doing desc sorts too.

  • #3
    Regular Coder
    Join Date
    Jan 2009
    Posts
    204
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Use a glob instead of opendir/readdir. I'm quite sure that one sorts by default.
    Glob will return an array as well, so you may want to capture it completely so you can use a sort on the array itself prior to iterating. This would work for doing desc sorts too.
    Thanks that's sorted it


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •