Help for folder listing

i must create a script that read all folders and subfolders on a server

i found this script :

(PHP)
<?php
// Note that !== did not exist until 4.0.0-RC2
$dir=$_POST[‘dir’];

if ($handle = opendir($dir)) {
echo "Directory handle: $handle
";
echo "Files:
";

// Counter
$i=0;

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
$return.="&item".$i."=".$file."
";
$i++;

}

closedir($handle);

}
echo $return."&n=".$i;
?>

(FLASH)
var lv = new LoadVars();
lv.onLoad = function() {
var count:Number = parseInt(this[‘n’]);
for (var i = 0; i<count; i++) {
var currItem = this[‘item’+i];

   //Check to see if its a folder or not
    if (currItem.indexOf(".") == -1) {
        var Branch = myTree.addTreeNode(currItem, "/"+currItem);
        myTree.setIsBranch(Branch, true);

    } else {
        myTree.addTreeNode(currItem, "/"+currItem);
    }
}

};
lv.dir = “prova”;
lv.sendAndLoad(“dir.php”, lv, “POST”);

but this script read only the first folder.
ther’s a way to read (with php) all folders and subfolders on server and publish somthing like:

firstfolder/firstsubfolder/etc…
secondfolder/firstsubfolder/etc…
etc…

thanks for help

(sorry for my english)