- /**
- * 获取目录的结构
- * @author 李俊 <duguying2008@gmail.com>
- * @param [string] $path [目录路径]
- * @return [array] [目录结构数组]
- */
- function dirtree($path) {
- $handle = opendir($path);
- $itemArray=array();
- while (false !== ($file = readdir($handle))) {
- if (($file=='.')||($file=='..')){
- }elseif (is_dir($path.$file)) {
- try {
- $dirtmparr=dirtree($path.$file.'/');
- } catch (Exception $e) {
- $dirtmparr=null;
- };
- $itemArray[$file]=$dirtmparr;
- }else{
- array_push($itemArray, $file);
- }
- }
- return $itemArray;
- }
- //该片段来自于http://www.codesnippet.cn/detail/311020136818.html
来源: http://www.codesnippet.cn/detail/311020136818.html