<?php
	session_start();

	if(isset($_GET[dir]))
	{
		$current_dir = realpath($_SESSION[current_dir]);
		if(strlen($current_dir) < strlen(realpath($current_dir . "/" . $_GET[dir])))
			$_SESSION[current_dir] = $current_dir . "/" . $_GET[dir];
	}
	else
	{
		$_SESSION[current_dir] = getcwd();
		$_SESSION[dir_root] = getcwd();
	}

	if($handle = opendir($_SESSION[current_dir]))
	{
		echo "Contents of folder " . $_SESSION[current_dir] . "\n<br>";

		while (false !== ($file = readdir($handle)))
		{
			if($file != ".")
			{
				if(is_dir($_SESSION[current_dir]."/".$file))
				{
					echo "[ <a href=\"$_SERVER[PHP_SELF]?dir=$file\">$file</a> ]<br>\n";
				}
				else
				{
					echo "<a href=\"$_SESSION[current_dir]/$file\">$file</a><br>\n";
				}
			}
		}

		closedir($handle);
	}
?>
