@@ 67-100 (lines=34) @@ | ||
64 | * @param bool $hidden Whether to show hidden files |
|
65 | * @return array |
|
66 | */ |
|
67 | function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) |
|
68 | { |
|
69 | if ($fp = @opendir($source_dir)) |
|
70 | { |
|
71 | $filedata = array(); |
|
72 | $new_depth = $directory_depth - 1; |
|
73 | $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
|
74 | ||
75 | while (FALSE !== ($file = readdir($fp))) |
|
76 | { |
|
77 | // Remove '.', '..', and hidden files [optional] |
|
78 | if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.')) |
|
79 | { |
|
80 | continue; |
|
81 | } |
|
82 | ||
83 | is_dir($source_dir.$file) && $file .= DIRECTORY_SEPARATOR; |
|
84 | ||
85 | if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir.$file)) |
|
86 | { |
|
87 | $filedata[$file] = directory_map($source_dir.$file, $new_depth, $hidden); |
|
88 | } |
|
89 | else |
|
90 | { |
|
91 | $filedata[] = $file; |
|
92 | } |
|
93 | } |
|
94 | ||
95 | closedir($fp); |
|
96 | return $filedata; |
|
97 | } |
|
98 | ||
99 | return FALSE; |
|
100 | } |
|
101 | } |
|
102 |
@@ 735-762 (lines=28) @@ | ||
732 | * @param bool $hidden Whether to show hidden files |
|
733 | * @return array |
|
734 | */ |
|
735 | protected function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) |
|
736 | { |
|
737 | if ($fp = @opendir($source_dir)) { |
|
738 | $filedata = array(); |
|
739 | $new_depth = $directory_depth - 1; |
|
740 | $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
741 | ||
742 | while (FALSE !== ($file = readdir($fp))) { |
|
743 | // Remove '.', '..', and hidden files [optional] |
|
744 | if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.')) { |
|
745 | continue; |
|
746 | } |
|
747 | ||
748 | is_dir($source_dir . $file) && $file .= DIRECTORY_SEPARATOR; |
|
749 | ||
750 | if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir . $file)) { |
|
751 | $filedata[$file] = directory_map($source_dir . $file, $new_depth, $hidden); |
|
752 | } else { |
|
753 | $filedata[] = $file; |
|
754 | } |
|
755 | } |
|
756 | ||
757 | closedir($fp); |
|
758 | return $filedata; |
|
759 | } |
|
760 | ||
761 | return FALSE; |
|
762 | } |
|
763 | ||
764 | //-------------------------------------------------------------------- |
|
765 |
@@ 400-432 (lines=33) @@ | ||
397 | * @param bool $hidden Whether to show hidden files |
|
398 | * @return array |
|
399 | */ |
|
400 | protected function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) |
|
401 | { |
|
402 | if ($fp = @opendir($source_dir)) { |
|
403 | $filedata = array(); |
|
404 | $new_depth = $directory_depth - 1; |
|
405 | $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
406 | ||
407 | while (FALSE !== ($file = readdir($fp))) { |
|
408 | // Remove '.', '..', and hidden files [optional] |
|
409 | if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.')) { |
|
410 | continue; |
|
411 | } |
|
412 | ||
413 | is_dir($source_dir . $file) && $file .= DIRECTORY_SEPARATOR; |
|
414 | ||
415 | if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir . $file)) |
|
416 | { |
|
417 | $filedata[$file] = $this->directory_map($source_dir . $file, $new_depth, $hidden); |
|
418 | } else |
|
419 | { |
|
420 | // Replace the directory separator here with a forward slash since |
|
421 | // Windows uses backward slashes and not all browsers will auto-replace |
|
422 | // those slashes in URLs. |
|
423 | $filedata[] = str_replace(DIRECTORY_SEPARATOR, '/', $file); |
|
424 | } |
|
425 | } |
|
426 | ||
427 | closedir($fp); |
|
428 | return $filedata; |
|
429 | } |
|
430 | ||
431 | return FALSE; |
|
432 | } |
|
433 | ||
434 | //-------------------------------------------------------------------- |
|
435 |