Code: Select all
function get_file_extension($filename) {
$extension = explode (".", $filename);
// -1 due to array starting with 0
$exten = (count($extension) - 1);
// Return it..
return $extension[$exten];
}
function read_dir_into_array($folder, $ext = 'jpg') {
global $files;
if ($handle = opendir($folder)) {
while (false !== ($file = readdir($handle))) {
// If the file is not .current dir, or ..up one dir, then continue
if ($file != "." && $file != "..") {
$file_ext = get_file_extension($file);
if ($file_ext == $file) {
read_dir_into_array($folder.$file);
}
elseif ($file_ext == $ext) {
$file = $folder . "/" . $file;
// replace // with /
$files[] = preg_replace("/\/\//si", "/", $file);
}
}
}
closedir($handle);
}
return $files;
}Code: Select all
- Defined
- dir1
* file1
* file2
* file3
* etc
- dir2
* file1
* file2
* file3
* etc
- dir3
* file1
* file2
* file3
* etc
- dir4
* file1
* file2
* file3
* etc
- dir5
* file1
* file2
* file3
* etcWhen I pass "defined" as the directory...
1. Every file in dir1 - dir5 gets included twice for some reason.
2. If I pass a lower level directory (ie. dir5), it still for some reason processes higher level directories and includes them in the array (so it still processes dir4, dir3, etc as well).
EDIT: I have found that even if I pass nothing to the function ie. read_dir_into_array()it still process the directories, and thus if i do pass a directory to it, then it process that directory again and adds it to the array, thus including it twice, any ideas why?? thanks.