sorting problem in PHP script

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

begeiste
New php-forum User
New php-forum User
Posts: 83
Joined: Thu Jun 03, 2004 11:27 am

sorting problem in PHP script

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

Hi,

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>";
      createDir($path.$dir."/");
      echo "</li>";
   }
   
   createDir($path);

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

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.


Return to “Your Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest