--- filebrowser-old/filebrowser.module	2008-01-17 23:24:09.000000000 -0700
+++ filebrowser/filebrowser.module	2008-04-20 12:55:09.000000000 -0600
@@ -35,10 +35,14 @@
   
   // Grab full Drupal path
   $curr_dir = substr($_GET['q'], strpos($full_path, $root_dir));
-  $curr_dir = str_replace($listing->path, $listing->location, $curr_dir);
+  $dir_wo_root = str_replace($listing->path, '', $curr_dir);
+  $dir_fs_root = str_replace($listing->path, $listing->location, $curr_dir);
   
+  // Reflect current directory in title
+  drupal_set_title(t('Directory %dir', array('%dir' => $dir_wo_root)));
+
   // Are we in a subdirectory?
-  $is_subdir = ($listing->location != $curr_dir);
+  $is_subdir = ($listing->location != $dir_fs_root);
   
   // If we shouldn't be in a subdir, redirect to root_dir
   if ($is_subdir && !$listing->can_explore) {
@@ -46,19 +50,18 @@
     drupal_goto($listing->path);
   }
   
-  // Reflect current directory in title
-  drupal_set_title(t('Displaying contents of directory %dir', array('%dir' => $curr_dir)));
 
-  $dir = $curr_dir;
+  $dir = $dir_fs_root;
   $files = array();
   $total_size = 0;
-  if (is_dir($dir) && $dh = opendir($dir)) {
+  if (is_file($dir)) {
+    drupal_goto($dir);
+  }
+  else if (is_dir($dir) && $dh = opendir($dir)) {
     while (($file = readdir($dh)) !== false && is_readable($dir .'/'. $file)) {
       $full_path = $dir .'/'. $file;
       if (is_file($full_path)) {
-        $f_size = filesize($full_path);
-        $total_size += $f_size;
-        $files[] = array(l($file, $full_path), format_size($f_size));
+        $files[] = $file;
       }
       // Keep a separate list of directories to append to beginning of array
       else if (is_dir($full_path)) {
@@ -70,6 +73,17 @@
     }
     closedir($dh);
   }
+
+  sort($files);
+  rsort($dirs);
+
+  $file_links = array();
+  foreach ($files as $file) {
+    $full_path = $dir .'/'. $file;
+    $f_size = filesize($full_path);
+    $total_size += $f_size;
+    $file_links[] = array(l($file, $full_path), format_size($f_size));
+  }
   
   if ($listing->can_explore) {
     foreach ($dirs as $dir) {
@@ -89,11 +103,11 @@
         t('Directory')
       );
       
-      array_unshift($files, $dir_row);
+      array_unshift($file_links, $dir_row);
     }
   }
   
-  $output = theme('table', array(t('Name'), t('Size')), $files);
+  $output = theme('table', array(t('Name'), t('Size')), $file_links);
   
   $output .= '<p>'. t('Contains @fc files totaling @ds in size', array('@fc' => count($files), '@ds' => format_size($total_size))) .'</p>';  
   
@@ -303,4 +317,4 @@
   }
   
   return array('file_count' => $file_count, 'total_size' => $total_size);
-}
\ No newline at end of file
+}
