/ Published in: PHP

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $tree = dir_tree($dir); function dir_tree($dir) { static $child = false; // Detect the current branch to append files/directories to { $branch =& $tree[$child]; } else { $branch =& $tree; } // Force trailing slash on directory // Find files/directories foreach($items as $key => $item) { // Get basename // always skip dot files if ($base[0] == '.') continue; // If file { $branch[] = $base; $child = false; continue; } // If directory { // Dirty hack to get around PHP's numerical index rules $base = '~'.$base; $child = $base; dir_tree($item); continue; } } // Only return from the root call if ($child === false) return $tree; }
Comments
