|
Posted by robert on 09/28/81 11:48
| function fileTree($directory,$ext)
| {
|
| $dir_array = array();
| $file_array = array();
|
| // what is the length of the extension
| $ExtLen = strlen($ext);
|
| if ($handle = opendir($directory))
| {
| while (false !== ($file = readdir($handle)))
| {
| if ($file != "." && $file != "..")
| {
| // this is a directory, so recurse down it
| if (is_dir($directory. "/" . $file))
| {
| $dir_array = array_merge($dir_array, $this->fileTree($directory.
| "/" . $file,$ext));
| $file = $directory . "/" . $file;
| $dir_array[] = preg_replace("/\/\//si", "/", $file);
| }
|
| // this is a file, test it, and add it to list if need be
| else
| {
|
| $file = $directory . "/" . $file;
|
| // overall length of the $file string
| $FileLen = strlen ($file);
|
| // now match the last N chars with the extension
| if ((substr ($file,($FileLen-$ExtLen),($FileLen))) == $ext)
| {
| $this->fileArray = array_merge($this->fileArray,$file);
| $file_array = array_merge($file_array,$file);
| }
|
| }
| }
| }
|
| closedir($handle);
| }
|
| // print out the array of files, to prove it is getting all the files
| foreach ($file_array as $wibble)
| {
| print "Wibble : $wibble <br>\n";
| }
|
| return ($file_array);
| }
you ARE missing something simple, chris. ;^)
think of why your wibble debug gets printed...then, think of what is being
returned by the function. obviously, you are overwritting your array in some
fashion as it is being built. look closer.
Navigation:
[Reply to this message]
|