Here is a quick and easy PHP script that will virtually list contents of any directory that it is placed in. Very easy and very handy and tested to work on HostNed FH1 server system (where .htaccess will not work).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>FileBrowser</title>
<style>
body {
font-family:Arial, Helvetica, sans-serif;
font-size:14px
}
.current_dir {
font-size:18px;
font-weight:bold
}
</style>
</head>
<body>
<center>
<div style="text-align:left; width:740px">
<div class="current_dir">
<?php
error_reporting(E_ALL);
$dir_name = explode("/", dirname(__FILE__));
if(isset($_GET['dir']) and file_exists($_GET['dir'])){
echo "./".$dir_name[count($dir_name)-1]."/".trim($_GET['dir'], "./")."/";
} else {
echo "./".$dir_name[count($dir_name)-1]."/";
}
?>
</div><br/>
<table border="1" cellspacing="0" cellpadding="2">
<tr><td width="40"><b>Type</b></td><td width="200"><b>Filename</b></td><td width="100"><b>Size</b></td><td width="300"><b>Date Modified</b></td><td width="100"><b>Permissions</b></td>
</tr>
<?php
// Settings //////////////
/* Only allow users to view the same directory this file is placed in. false: let users browse all directories */
$current_dir_only = false;
/* Hide certain file types. Example: $hide_files = array("php", "txt"); */
$hide_files = array();
//////////////////////////
if(isset($_GET['dir'])){
$dir = $_GET['dir'];
} else {
$dir = ".";
}
if($current_dir_only == true){
$dir = ".";
}
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file == ".." and isset($_GET['dir'])){
$back = explode("/", $_GET['dir']);
unset($back[count($back)-1]);
$link = implode("/", $back);
} else {
$link = $file;
$back = array();
}
// if dir exists, make the link to it
if(is_dir("./$dir/$link/")){
$link = "$dir/$link";
}
// .. link problem
if(count($back)-1 == 0 and is_dir("./$dir/$link/")){
$link = "";
} else {
$link = "dir=$link";
}
// as not to make ../dir/../beginning
if($file == ".." and count($back) == 1){
$link = "";
}
// link to file or dir
if(is_file(trim("$dir/$file", "dir="))){
$link = trim("$dir/$file", "dir=");
} else {
$link = "?{$link}";
}
if(is_file(trim("$dir/$file", "dir="))){
$filesize = round(filesize($link)/1000, 2);
$filesize .= "KB";
$modified = date("j/m/y h:i", filemtime($link));
$type = explode(".", $file);
$type = $type[count($file)];
$perm = substr(sprintf('%o', fileperms($link)), -4);
} else {
$dirname = trim("$dir/$file", "dir=");
$filesize = " ";
$modified = " ";
$type = "Dir";
if(file_exists($dirname)){
$perm = substr(sprintf('%o', fileperms("$dirname")), -4);
}
}
if($link == "?dir=./"){
$link = "?dir=../";
}
if($current_dir_only == true and $type == "Dir"){
$show_dir = 0;
} else {
$show_dir = 1;
}
if(!isset($_GET['dir']) and $file == ".."){
$no_go_back = true;
} else {
$no_go_back = false;
}
if($file != "."){
if($no_go_back == false){
if($show_dir != 0){
if(!in_array($type, $hide_files)){
echo "<tr><td>$type</td><td><a href=\"$link\">$file</a></td><td>$filesize</td><td>$modified</td><td>$perm</td></tr>\n";
}
}
}
}
}
closedir($dh);
}
}
?>
</table>
</div>
<br />
<!-- Do not remove this notice -->
Powered by <a href="http://www.publicwarehouse.co.uk">FileBrowser</a> © Copyright 2007 Peter Bailey
<!-- Do not remove this notice -->
</center>
</body></html>