Public paste
Voor jouw Thomas!
By: Xmoo | Date: Nov 27 2006 21:38 | Format: PHP | Expires: never | Size: 3.25 KB | Hits: 1422

  1. <?
  2.     //Bestanden die niet weergegeven worden
  3.     $exclude = Array(".","..",".php",".htm",".html",".css",".sql",".inc");
  4.  
  5.     //Het complete path van het script
  6.     $standpath = substr($_SERVER["SCRIPT_FILENAME"],0,strrpos($_SERVER["SCRIPT_FILENAME"],"/"));
  7.  
  8.     //Check naar welke directory er gegaan moet worden
  9.     If ($_GET[newdir]) {
  10.         (file_exists($standpath . "/" . $_GET[newdir])) ? $standpath = $standpath . "/" . $_GET[newdir] : header("Location: ?show=files");
  11.     }
  12.    
  13.     //Lees elke file en directory uit de geopende directory en zet deze beide een aparte array
  14.     $wdir = opendir($standpath);
  15.     while (false !== ($filename = readdir($wdir))) {
  16.         If (!in_array(substr($filename,strrpos($filename,".")),$exclude)) {
  17.             (is_dir($standpath . "/" . $filename)) ? $all_dirs[] = $filename : $all_files[] = $filename;
  18.         }
  19.     }
  20.  
  21.     //Sorteer beide array's
  22.     If ($all_dirs) sort($all_dirs);
  23.     If ($all_files)    sort($all_files);
  24.  
  25.     //Voeg de beide array's samen
  26.     $totaldir = array_merge_recursive($all_dirs,$all_files);
  27.  
  28.     //Loop alle files en directory's afzonderlijk na
  29.     $counter = 0;
  30.     While ($totaldir[$counter]) {
  31.  
  32.         //Check of het een directory of een file is
  33.         If (is_dir($standpath . "/" . $totaldir[$counter])) {
  34.             $ftype = "Directory";
  35.             $link = $_SERVER['PHP_SELF'] . "?show=files&newdir=" . $_GET[newdir] . "/" . $totaldir[$counter];
  36.             $fsize = "";
  37.         } Else {
  38.  
  39.             //Bereken bestandsgroote in Bytes, KiloBytes, MegaBytes of GigaBytes
  40.             $fsize = filesize($standpath . "/" . $totaldir[$counter]);
  41.             If ($fsize < 1024) $fsize .= " B";
  42.             ElseIf ($fsize < 1048576) $fsize = round($fsize / 1024,2) . " KB";
  43.             ElseIf ($fsize < 1073741824) $fsize = round($fsize / 1024 / 1024,2) . " MB";
  44.             ElseIf ($fsize < 1099511627776) $fsize = round($fsize / 1024 / 1024 / 1024,2) . " GB";
  45.  
  46.             //Maak een HTML link
  47.             $ftype = "File";
  48.             ($_GET[newdir]) ? $link = substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/")) . $_GET[newdir] . "/" . $totaldir[$counter] : $link = $totaldir[$counter];
  49.         }
  50.         ($_GET[newdir]) ? $location = $_GET[newdir] : $location = "/";
  51.        
  52.         //Maak de HTML source
  53.         $files .= "
  54.                    <tr>
  55.                        <td class="type">" . $ftype . "</td>
  56.                        <td class="link"><a href="" . $link . "">" . $totaldir[$counter] . "</a></td>
  57.                        <td class="path">" . $location . "</td>
  58.                        <td class="size">" . $fsize . "</td>
  59.                        <td class="modified">" . date("d-m-Y H:i", filemtime($standpath . "/" . $totaldir[$counter])) . "</td>
  60.                    </tr>";
  61.         $counter++;
  62.     }
  63. ?>
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. <?    
  73.     //Een 'Parent Directory' link maken
  74.     If ($_GET[newdir]) {  ?>
  75.                     <tr>
  76.                         <td colspan="5"><a href="<? echo $_SERVER['PHP_SELF'] . "?show=files&newdir=" . substr($_GET[newdir],0,strrpos($_GET[newdir],"/")); ?>">Parent Directory</a></td>
  77.                     </tr>
  78. <?
  79.     }
  80.     echo $files;
  81. ?>