NoPaste

phpbrowser

von thorben

SNIPPET_TEXT:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2.  <html><head><title>
  3.    Filebrowser v1.0 -- Peer Heinlein
  4.  </title></head>
  5.  <body>
  6. <?
  7.  if(isset($_GET['path'])) {
  8.    // Variable einlesen (register_globals=off)
  9.    $path = $_GET['path'];
  10.  
  11.    // Wenn Datei, dann Inhalt zeigen
  12.    if(is_file($path)) {
  13.      $file = fopen($path,"r");
  14.      print "<pre>";
  15.     while (!feof($file)) {
  16.        $zeile = fgets($file, 4096);
  17.        print htmlentities($zeile,ENT_QUOTES);
  18.      }
  19.      print "</pre></body></html>";
  20.      fclose($file);
  21.      exit;
  22.   }
  23.  
  24.    // Wenn Pfad, dann Verzeichnislisting
  25.   print "<pre><b>Inhalt von $path</b> <br><br>";
  26.   $dir = opendir($path);
  27.    while($file = readdir($dir)) {
  28.     $filepath = $path . "/" . $file;
  29.      if(is_dir($filepath))
  30.        print "[DIR ] ";
  31.     elseif(is_file($filepath))
  32.        print "[FILE] ";
  33.      elseif(is_link($filepath))
  34.      print "[LINK] ";
  35.      else
  36.        print "       ";
  37.  
  38.      if($file == ".")
  39.        print "<a href=\"" . $_SERVER['PHP_SELF']
  40.        . "?path=$path\">.</a><br>";
  41.      elseif($file == "..") {
  42.        if(substr($path,0,strrpos($path,"/")) == "") {
  43.          print "<a href=\""
  44.            . $_SERVER['PHP_SELF']
  45.            . "?path=/\">..</a><br>";
  46.        } else {
  47.          print "<a href=\""
  48.            . $_SERVER['PHP_SELF']
  49.            . "?path="
  50.            . substr($path,0,strrpos($path,"/"))
  51.            . "\">..</a><br>";
  52.        }
  53.      }
  54.  else {
  55.        print "<a href=\""
  56.         . $_SERVER['PHP_SELF']
  57.          . "?path="
  58.          . (($path == "/") ? "" : $path)
  59.          . "/" . rawurlencode($file)
  60.          . "\">$file</a>";
  61.  
  62.        // Dateieigenschaften auflisten
  63.        $mode = (is_writeable($filepath)) ?
  64.          ", mode: writeable " : "";
  65.        $stat = stat($filepath);
  66.        $uid = $stat[4];
  67.        $gid = $stat[5];
  68.        $size = $stat[7];
  69.        print "    [ uid: $uid, gid: $gid, size: $size $mode]";
  70.      }
  71.    }
  72.    closedir($dir);
  73.    print "</pre>";
  74. } else {
  75. ?>
  76.  <form action="" method="get">
  77.    Verzeichnis?<br>
  78.    <input type="text" name="path">
  79.    <br><br>
  80.    <input type="submit" value="anzeigen">
  81.  </form>
  82.  <?
  83.  }
  84.  ?>
  85.  </body>
  86. </html>

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN