/ Published in: PHP
There are a lot of recursive glob functions out there but they don't build a tree, they build a 1 dimensional array...This function builds a directory tree.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* to use: pattern = glob pattern to match flags = glob flags path = path to search depth = how deep to travel, -1 for unlimited, 0 for only current directory */ $folders = folder_tree('*.*', 0, '/path_here/', -1); function folder_tree($pattern = '*', $flags = 0, $path = false, $depth = 0, $level = 0) { $level++; foreach ($paths as $sub_path) { $tree[$sub_path] = folder_tree($pattern, $flags, $sub_path.DIRECTORY_SEPARATOR, $depth, $level); } } return $tree; }