Dieses PHP Snippet von Sick^ zeigt euch, wie man alle Ordner rekursiv bekommen kann.
PHP
- ´/**
- * Function to retrieve hierarchical Folder structure
- * @param type $path String path of Folder
- * @param type $depth Int The hierarchical folder depth
- * @return type return array of Folders in hierarchical structure
- */
- function getFolders($path, $depth = 0) {
- // if deptch is to low return
- if ($depth < 0) {
- return array();
- }
- // get all elements inside $path
- $folders = scandir($path);
- $return = array();
- // loop all elements
- foreach ($folders AS $folder) {
- // check if current element is a folder and it is not a backlink (. or ..)
- if (is_dir($path.'/'.$folder) && !in_array($folder, array('.', '..'))) {
- // get child folders
- $return[$path.'/'.$folder] = getFolders($path.'/'.$folder, $depth-1);
- }
- else {
- continue;
- }
- }
- // return current folder level
- return $return;
- }
- // get all folders inside the directory of these file
- var_dump(getFolders(dirname(__FILE__), 1));
Termi