In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] 
says...
> First I must state that I didn't write the code, and I'm not much of a programmer of 
>any kind.  I'm hoping someone can tell me how to sort the filenames and file sizes 
>returned by readdir and filesize in the below code.  Thanks in advance.
> 
> dan
> 
> 
> <?
> 
> function list_dir($dir)
>         {
>                 $handle=opendir($dir);
>                 echo "<ul>";
>                 while ($file = readdir($handle))
>                 {
>                     if ($file != '.' && $file != '..'  && !ereg("\.php$", $file)) {
>                 print ("<tr>\n<td>\n");
>                                 print ("<li><a
> href=\"".$GLOBALS["path"].$file."\">".$file."</a>");
>                 print ("</td>\n");
>                                 if (is_dir($file))
>                                         {
>                         printf ("<td>");
>                                                 $toto = $GLOBALS["path"];
>                                                 $GLOBALS["path"] .= $file."/";
>                                                 chdir ($file);
>                                                 list_dir(".");
>                                                 $GLOBALS["path"] = $toto;
>                                                 chdir ("..");
>                         printf ("</td>");
>                                         } else {
>                         printf ("<td>\n");
>                                                 $size = filesize($file);
>                                                 if ($size == NULL)
>                                                         $size = "<unknown>";
>                                                 printf ("&nbsp;".$size." 
>&nbsp;bytes\n");
>                         printf ("</td>\n");
>                                         }
>                    print ("</tr>\n");
>             }
>                 }
>                 echo "</ul>";
>                 closedir($handle);
>         }
> 
> $directory = "screenshots";
> 
> $GLOBALS["path"] = "http://".$HTTP_HOST."/".$directory."/";;
> 
> echo "<table>\n";
> list_dir("."); 
> echo "</table>";

The short answer (well, one of) is that you extract your file information 
into arrays, which you can then sort using the various array sorting 
tools. Tthen, having sorted the aray as you desire, step through the 
array and display the contents with whatever formatting you need.

If you need more help with this, I think I have some functions which 
could be fairly easily modified to use file size as well as name; but 
I'll have to scratch around in the Linux partition of my lapdog to find 
and test them.

-- 
David Robley
Temporary Kiwi!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to