How to sort a dynamic PHP list being echoed?
===

Let me tell you first what I'm trying to achieve. We have a need to display documents on our website from within a folder on that same server. This website is a flat file site hence no databases are involved just PHP and CGI. 

the source code can be found here alongside the demo:

> http://www.peakcustomers.co.uk/kris.php
      <html>
      <body>
      <h3>Resources and Downloads</h3>

      <?php

      $folder = "uploads/";
      $handle = opendir($folder);

      function ListFolder($path)
      {
    //using the opendir function
    $dir_handle = @opendir($path) or die("Unable to open $path");
  
    //Leave only the lastest folder name
    $dirname = end(explode("/", $path));
   
    //display the target folder
    echo ("<li><h3>$dirname</h3>");
    echo "<ul>";

    while (false !== ($file = readdir($dir_handle)))
    {
        if($file!="." && $file!="..")
        {
            if (is_dir($path."/".$file))
            {
                //Display a list of sub folders.
                ListFolder($path."/".$file);
            }
            else
            {
                echo "<a href='$path/$file'><img src=http://www.webbholton.co.uk/img2.gif></a> <a href='$path/$file'>$file</a>"."<br />";
            }
        }
    }
    echo "</ul>";
    echo "</li>"; 

    //closing the directory
    closedir($dir_handle);
      }
      ?>


      <script language="JavaScript" type="text/javascript">
      <!--
      dmxListToTree({
        bullets : 'plusminus',
        icons   : true,
        struct  : false,
        objId   : 'FolderView'
      });
      //-->
      </script>
      <ul class="dmxtree" id="FolderView">
      <?php ListFolder("Documents"); ?>
      </ul>
      </body>
      </html>'



Using this code, the website reads the folder on the web server called Documents and prints them nicely onto the screen along with links to the subsequent docs or pdfs to be read by our clients. 

I need a way to sort this list though, at the moment it is sorted by order of creation going down the page (I believe). 

I.E 
2012
     - doc1
2013
     - doc2

etc etc, I need this to be in the opposite order. 

Thanks and appreciate any advice people can offer..

