Basically, what I want to do is starting from a certain directory, get all the files and directorys and stick them in an array. Then open all directorys again, and stick them in an array, then so on and so on...currently the code i'm using is below
function dirOpen($dir,$num=0) { // $dir = Directory to open, $num=No of spaces to indent files
$array = array("dir","file");
if ($handle = opendir($dir)) { // Open up the directory
while (false !== ($file = readdir($handle))) { // Read the contents
// strip out . and ..
if ($file != "." && $file != "..") {
if( @is_dir($file) ) {
// Add the directory to array
$array["dir"][] = $file;
}else {
// Add the file name to the array without the document_root
$array["file"][] = eregi_replace($_SERVER['DOCUMENT_ROOT'],"",$dir."/".$file);
}
}
}
closedir($handle); // Close the directory
}
if( !empty($array["dir"]) ) {
// If there is directorys, display them all
foreach($array["dir"] as $dirName) {
// Display Directory Name with indentation
echo str_repeat(" ",$num)."<strong>".$dirName."</strong>\n<br>";
// Open up this directory, and check for contents
dirOpen($dir."/".$dirName,$num+5);
}
}
if( !empty($array["file"]) ) {
// If there is files, display them all
foreach($array["file"] as $fileName) {
// Display Filename in Directory tree
echo str_repeat(" ",$num).$fileName."\n<br>";
}
}
return $array;
}
echo "<h2>DIRECTORY LISTING</h2>\n";
$array = dirOpen($_SERVER['DOCUMENT_ROOT']);
print_r($array);
Problem is, that only stores the files and directorys from the original directory that's being opened. Anyone have a solution as to how I could solve this problem?