Hi. I'm trying to write a simple PHP file browser that will parse a folder and display all the files and folders contained within it. The folders have to be clickable and open the folder and repeat the process. Also, i have to process the ".." directory so that the actual path of the parent folder is displayed as opposed to "/../". I need help with this last requirement. Here is my attempt to do that, which does not work. How can I fix this to display the path properly?
CODE
<HTML>
<HEAD><TITLE> PHP File Browser </TITLE></HEAD>
<BODY>
<?PHP
if(isset($_GET["path"]))
{
$path= $_GET["path"];
}
else
$path="C:\Documents and Settings\HP_Administrator\My Documents";
if(!($check = chdir($path)))
{
echo "Error! Path Not Found!";
}
else
{
$folder = opendir($path);
$free = diskfreespace($path);
echo "Let's check $path.<BR>\n";
echo "It has $free bytes free.<BR>\n";
$arr = scandir($path);
$directories;
$files;
$a = 0;
$b = 0;
foreach($arr as $e)
{
if(is_dir($e))
{
$directories[$a] = $e;
$a++;
}
else if(is_file($e))
{
$files[$b] = $e;
$b++;
}
}
echo "<BR>";
natcasesort($directories);
natcasesort($files);
foreach($directories as $el)
{
if($el != ".")
{
/* if($el != "..")
{*/
echo "<A HREF="."\"http://localhost/file_browser.php?path=$path/".$el."\">"."$el"."</A>";
echo "<BR>\n";
/*}
else
{
$n = strrpos($path, "\\");
$path2 = substr($path, 0, n);
echo "<A HREF="."\"http://localhost/file_browser.php?path=$path2\">"."$el"."</A>";
echo "<BR>\n";
}*/
}
}
echo "<BR>\n";
foreach($files as $elem)
{
echo $elem;
echo "<BR>\n";
}
}
function superExplode($str, $sep)
{
$i = 0;
$arr[$i++] = strtok($str, $sep);
while ($token = strtok($sep))
$arr[$i++] = $token;
return $arr;
}
?>
</BODY>
</HTML>