<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>
  Filebrowser v1.0 -- Peer Heinlein
</title></head>
<body>
<?
if(isset($_GET['path'])) {
  // Variable einlesen (register_globals=off)
  $path = $_GET['path'];

  // Wenn Datei, dann Inhalt zeigen
  if(is_file($path)) {
    $file = fopen($path,"r");
    print "<pre>";
    while (!feof($file)) {
      $zeile = fgets($file, 4096);
      print htmlentities($zeile,ENT_QUOTES);
    }
    print "</pre></body></html>";
    fclose($file);
    exit;
  }

  // Wenn Pfad, dann Verzeichnislisting
  print "<pre><b>Inhalt von $path</b> <br><br>";
  $dir = opendir($path);
  while($file = readdir($dir)) {
    $filepath = $path . "/" . $file;
    if(is_dir($filepath))
      print "[DIR ] ";
    elseif(is_file($filepath))
      print "[FILE] ";
    elseif(is_link($filepath))
      print "[LINK] ";
    else
      print "       ";

    if($file == ".")
      print "<a href=\"" . $_SERVER['PHP_SELF']
       . "?path=$path\">.</a><br>";
    elseif($file == "..") {
      if(substr($path,0,strrpos($path,"/")) == "") {
        print "<a href=\""
          . $_SERVER['PHP_SELF']
          . "?path=/\">..</a><br>";
      } else {
        print "<a href=\""
          . $_SERVER['PHP_SELF']
          . "?path="
          . substr($path,0,strrpos($path,"/"))
          . "\">..</a><br>";
      }
    }
    else {
      print "<a href=\""
        . $_SERVER['PHP_SELF']
        . "?path="
        . (($path == "/") ? "" : $path)
        . "/" . rawurlencode($file)
        . "\">$file</a>";

      // Dateieigenschaften auflisten
      $mode = (is_writeable($filepath)) ?
        ", mode: writeable " : "";
      $stat = stat($filepath);
      $uid = $stat[4];
      $gid = $stat[5];
      $size = $stat[7];
      print "    [ uid: $uid, gid: $gid, size: $size $mode]";
    }
  }
  closedir($dir);
  print "</pre>";
} else {
?>
<form action="" method="get">
  Verzeichnis?<br>
  <input type="text" name="path">
  <br><br>
  <input type="submit" value="anzeigen">
</form>
<?
}
?>
</body>
</html>