<?php
$PHP_SELF = $_SERVER['PHP_SELF'];
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$tdir = $_GET['dir'];
echo "tdir==$tdir<br>";
$tparent_path = $_GET['parent_path'];
$dbg = $_GET['dbg'];
if(!strstr($tdir, $DOCUMENT_ROOT))
$tdir = getcwd();
if(!strstr($tparent_path, $DOCUMENT_ROOT))
$tparent_path = $tdir;
if (!isset ($tdir))
{
$dir = getcwd ();
}
else
$dir = $tdir;
if (!isset ($tparent_path))
{
$parent_path = $dir;
}
else
$parent_path = $tparent_path;
echo "<br>";
if (!isset ($tdir))
{
$upurl = $PHP_SELF;
}
else
{
if ($parent_path == $DOCUMENT_ROOT)
$parent_parent_path = $parent_path;
else
$parent_parent_path = dirname ($parent_path);
$upurl = $PHP_SELF."?dir=".$parent_path."&parent_path=".
$parent_parent_path;
}
if($dbg==1)
{
echo "PHP_SELF: $PHP_SELF<br>\n";
echo "DOCUMENT_ROOT: $DOCUMENT_ROOT<br>\n";
echo "dir: $dir<br>\n";
echo "parent_path: $parent_path<br>\n";
echo "upurl: $upurl<br>\n";
}
echo "<a href=\"$upurl\"> <h3>Up</h3> </a>\n";
echo "<h2>$dir</h2>\n";
create_tree ($dir, $parent_path);
function
urlFromPath ($path)
{
global $PHP_SELF;
global $DOCUMENT_ROOT;
$prefix = "";
if (substr ($path, 0, 1) != "/")
$prefix = "/";
$url = $prefix.ereg_replace ($DOCUMENT_ROOT, "", $path);
return $url;
}
function
create_tree ($dir, $parent_path)
{
if ($handle = opendir ($dir))
{
$i = 0;
while (false !== ($file = @readdir ($handle)))
{
if ($file != "." && $file != "..")
{
$list[$i] = $file;
$i++;
}
}
$dir_length = count ($list);
echo "<ul>";
for ($i = 0; $i < $dir_length; $i++)
{
global $PHP_SELF;
global $DOCUMENT_ROOT;
$label = $list[$i];
$test = $dir."/".$label;
$alink = $dir."/".ereg_replace(" ","%20",$label);
if (!strstr ($PHP_SELF, $label))
{
if (is_dir ($test))
{
$tmp = $PHP_SELF. "?dir=".$alink."&parent_path=".$dir;
$url = ereg_replace(" ", "%20", $tmp);
echo "$url<br>\n";
echo "<a href=\"$url\"><b>$label</b>/</a><br>\n";
}
else
{
$link = urlFromPath ($alink);
$label = $list[$i];
echo
"<a href=\"$link\">".$label."</a><br>\n";
}
}
}
echo "</ul>";
closedir ($handle);
}
}
?>