Here is one of the user notes in the manual entry for readdir() (credit given there)
Taking the GetDirArray() function above and adding some recurssion in to list the entire contents of a dir and the tree below:
function GetDirArray($sPath)
{
//Load Directory Into Array
$handle=opendir($sPath);
while ($file = readdir($handle))
{
$retVal[count($retVal)] = $file;
}
//Clean up and sort
closedir($handle);
sort($retVal);
//return $retVal;
while (list($key, $val) = each($retVal))
{
if ($val != "." && $val != "..")
{
$path = str_replace("//","/",$sPath.$val);
echo "$path
";
if (is_dir($sPath.$val))
{
GetDirArray($sPath.$val."/");
}
}
}
}