Board index   FAQ   Search  
Register  Login
Board index PHP Your Scripts

sorting problem in PHP script

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

sorting problem in PHP script

Postby begeiste » Tue Aug 16, 2011 10:51 am


Can someone please help me out for the sorting problem for this php script? Because there is no an ability for sorting directories or files?

Any responses will be greatly appreciated it.

Code: Select all
$path = "docs/";

   function createDir($path = '.')
      if ($handle = opendir($path))
         echo "<ul>";
         while (false !== ($file = readdir($handle)))
            if (is_dir($path.$file) && $file != '.' && $file !='..')
               printSubDir($file, $path, $queue);
            else if ($file != '.' && $file !='..')
               $queue[] = $file;
         printQueue($queue, $path);
         echo "</ul>";
   function printQueue($queue, $path)
      foreach ($queue as $file)
         printFile($file, $path);
   function printFile($file, $path)
      echo "<li><a href=\"".$path.$file."\" target=\"_blank \">$file</a></li><br><br>";
   function printSubDir($dir, $path)
      echo "<li><span class=\"toggle\">$dir</span>";
      echo "</li>";
New php-forum User
New php-forum User
Posts: 83
Joined: Thu Jun 03, 2004 11:27 am

Re: sorting problem in PHP script

Postby egami » Wed Aug 17, 2011 4:15 am

There is, you just create an array from the file listing, then sort the array.
User avatar
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Return to Your Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.