$value) { if (isIgnored($value)) { continue; } if ($relPath == '') { $filePath = $value; } else { $filePath = $relPath . DIRECTORY_SEPARATOR . $value; } if (is_dir(getAbsolutePath($filePath))) { if ($mode == 'folders') { $result = array_merge($result, (array)$filePath); } if ($recurse) { $result = array_merge($result, getAllFilesUnderAsArray($filePath, $recurse, $mode)); } } else if ($mode == 'files') { $result = array_merge($result, (array)$filePath); } } return $result; } function main() { global $rootDir; if (!isset($_GET['separator'])) { $separator = "\n"; } else { $separator = $_GET['separator']; } $recurse = (strtolower($_GET['recurse']) != 'false'); if (strtolower($_GET['mode']) == 'folders') { $mode = 'folders'; } else { $mode = 'files'; } # Very primitive check if path tries to go above DOCUMENT_ROOT or is absolute $path = $_GET['path']; if (strpos($path, "..") !== False || substr($path, 0, 1) == DIRECTORY_SEPARATOR) { return; } # If we don't want realpath to append any prefixes we need to pass it an absolute path $relPath = substr(realpath(getAbsolutePath($path)), strlen($rootDir) + 1); # If the path is not found, return nothing. if ($path !== "" && $relPath == "") return; # If there is an error of some sort it will be output as a part of the answer! foreach (getAllFilesUnderAsArray($relPath, $recurse, $mode) as $i => $value) { echo "$value$separator"; } } main(); ?>