Here's a function that I use to recursively list all directories and subdirectories under a given directory:
function dirTree( &$dirArray,$baseDir) {
if ($handle = opendir($baseDir)) {
while (false !== ($file = readdir($handle))) {
$dotPos=strpos($file,'.'); //checks if first character of file is a dot (.)
if ( ($dotPos > 0) || ($dotPos === false)) {
$path=$baseDir."/".$file;
if (is_dir($path) ) { //checks to see if file is a directory
$dirArray[]=$path;
dirTree($dirArray,$path); //recursively checks all subdirectories
}
}
}
}
closedir($handle);
return;
}
To use it, define some empty array and call the function, such as
$path="/path/you/want/to/list";
$dirs=array();
dirTree($dirs,$path);
The $dirs array will have the directory names for all subdirectories in the path.
Hope this helps.