Hello --
I am having a trouble with my code, which reads a document directory recursively. My idea is that I call a function rmenu() from mainfunction.php file and get an array of directory information and parse it into a table.
I wrote a function, rmenu()
function rmenu($dir, $j) {
global $docRoot, $urlDir, $articles, $docPath;
$content="";
$menuContent="";
if ($handle=@opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if (is_dir($dir."/".$file)) {
if ($file != "." && $file != "..") {
$dA[]=$file;
}
}
else {
$fA[]=$file;
}
}
closedir($handle);
}
for ($i=0;$i<sizeof($fA);$i++) {
if (is_file($dir."/".$fA[$i])) {
// debugging... echo "Fileanme : {$fA[$i]} === under Dir: $dir <br>";
}
}
$j++;
for ($i=0;$i<sizeof($dA);$i++) {
rmenu("$dir"."/"."$dA[$i]", $j);
}
return $fA;
}
While this function reads directories and files ok, return values keep changing (first it returns files in parent directory; and returns files in its subdirectories; then their subdirectories; and so on...).
As a result of this, I only get the last array of $fA.
I want to gather them into one array and return it to a php file; and render the directory within a table. "Gather them into one array" is my problem....
Oh, if I make echo statements here and there, I get all the information. But, this would not help me since I need to parse the information into a table in a php file (index.php). That is, the echo statements will show before the page design...
Any help would be appreciated...
Thanks.