//define the path as relative
$path = '.';
$leadin = " •   ";
$spacer = " ";
$dir = getcwd();
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
$last = substr(strrchr($dir, '/'), 1);
echo "Directory Listing for $last";
$cnt = 0;
while ($file = readdir($dir_handle))
{
if($file!="." && $file!="index.php")
{
$listFile[$cnt] = $file;
$cnt++;;
}
}
if($cnt > 0)
{
$lf = 0;
sort($listFile);
echo $spacer."Parent Directory"."
";
for($k = 0; $k < $cnt; $k++)
{
$file = $listFile[$k];
if(filetype($file) == "dir")
{
if($file != "..")
{
echo $spacer."[Folder]".$spacer."$file"."
";
$lf = 1;
}
}
}
if($lf) echo "
";
for($k = 0; $k < $cnt; $k++)
{
$file = $listFile[$k];
if(filetype($file) != "dir")
{
echo $leadin."$file"."
";
}
}
}
//closing the directory
closedir($dir_handle);
?>