#native_company# #native_desc#
#native_cta#

File Manager

By Slash Steiner
on October 9, 2006

Version: 0.0.1

Type: Full Script

Category: File Management

License: GNU General Public License

Description: Browse files and folders in just one module.

<?
# Default directory
//$dir = "http://".$_SERVER['HTTP_HOST']."/";
$dir = "../".dirname($_SERVER['PHP_SELF'])."/";
if(!empty($_GET['f']) && is_dir($_GET['f'])) $dir = $_GET['f'];
$defaultDir = $dir;

# Check if there is a value set for folder or file
if(isset($_GET['p'])){
  $tmp = $_GET['p'];
  $type = $_GET['t'];
  if($type=="d"){
    $tmp .= "/";
    if(is_dir("$dir$tmp")){
      $dir .= $tmp;
    }
  }
  else {
    $tmp = "$dir$tmp";
    $fileExt = substr($tmp,strlen($tmp)-3);
    $contentType = mime_content_type($tmp);
    /*
      Expected content-types:
        video/x-msvideo
        video/mpeg
    */

    header("Content-Type: $contentType");
    header("Content-disposition: attachment; filename=$tmp");
    readfile($tmp);
  }
}
?>
<html>
<head>
<title>File Manager</title>
</head>

<style>
a {text-decoration:none;}
</style>

<body>
<?
// Open a known directory, and proceed to read its contents
$result = "";
if (is_dir($dir)) {
  if ($dh = opendir($dir)) {
    while(($file = readdir($dh)) !== false) {
      $origFile = $file;
      $fileType = filetype($dir . $file);
      $href = "?p=$file&f=$dir";
      if($fileType=="dir"){
        $href .= "&t=d";
        $file = "<font style='font-size:12px; color:green; text-decoration:underline'>$file</font>";
      }
      else $file = "<font style='font-size:12px; color:blue;'>$file</font>";

      if($origFile=="..") $result = "<a href='$href'><b>$file</b></a><br>$result";
      else if($origFile!=".") $result .= "<a href='$href'>$file</a><br>";
    }
    closedir($dh);
  }
}
?>
<?=$result?>
</body>
</html>