生成目录树形结构
2015-04-13 11:32
281 查看
<?php echo '<script src="http://code.jquery.com/jquery.min.js"></script>'; echo '<script> function showpath(str,t){clearTimeout(t);$("#file-path").remove();$("<div id=\'file-path\'></div>").appendTo("body").html(str);t=setTimeout("$(\'#file-path\').fadeOut()",10000);return t;} $(function(){ var t={}; $(".expandable").click(function(){event.preventDefault();event.stopPropagation();$(this).children().toggle();}); $(".file").click(function(){event.stopPropagation();event.preventDefault();}); $(".file").click(function(){var tmpstr="";clearTimeout(t); $(this).parents("li").each(function(){tmpstr=($(this)[0].firstChild.nodeValue+"→"+tmpstr);}); tmpstr+=$(this).text();t=showpath(tmpstr,t); });$("body").on("click","#file-path",function(){clearTimeout(t);$(this).fadeOut();}); });</script>'; echo '<style>.expandable{cursor:pointer;font-weight:bold}.file{color:blue;cursor:pointer;}#file-path{font-size:20px;font-weight:bold;position:fixed;width:98%;cursor:pointer;padding:10px 15px;text-align:center;top:0px;box-sizing:border-box;left:1%;border:2px solid black;background:rgba(0,188,188,0.6);border-radius:5px;}</style>'; function traverse($path, $x, $y) { $current_dir = opendir($path); while (($file = readdir($current_dir)) !== false) { $sub_dir = $path . DIRECTORY_SEPARATOR . $file; //构建子目录路径 if ($file == '.' || $file == '..') { continue; } else if (is_dir($sub_dir)) { for ($i = 0; $i < $x; $i++) { echo "│"; } echo "│┼" . $file . "<br>"; traverse($sub_dir, $x + 1, $y + 1); } else { for ($i = 0; $i < $x; $i++) { echo "│"; } echo "│├" . $file . "<br>"; } } } $countFile = 0; function traverse2($path, $x, $y) { global $countFile; $current_dir = opendir($path); while (($file = readdir($current_dir)) !== false) { $sub_dir = $path . DIRECTORY_SEPARATOR . $file; //构建子目录路径 if ($file == '.' || $file == '..') { continue; } else if (is_dir($sub_dir)) { echo "<li class='expandable level" . $x . "'>" . $file . "<ul>"; traverse2($sub_dir, $x + 1, $y + 1); echo "</ul></li>"; } else { // if (substr($file, -3) == 'php') { $countFile++; // echo "<li class='file'>" . $file . "</li>"; // } echo "<li class='file'>" . $file . "</li>"; } } } echo "<div id='control'><button onclick='$(\".expandable\").children().hide();'>全部折叠</button><button onclick='$(\".expandable\").children().show();'>全部展开</button></div>"; echo "<ol style='position:relative;'>"; traverse2('.', 0, 0); echo "</ol>"; echo "<p style='clear:both;position:relative'>共计" . $countFile . "个文件</p>"; // traverse(".", 0, 0); ?>
相关文章推荐
- php+jquery读取文件目录生成树形结构
- 在Web界面下如何生成像资源管理器一样的树形目录
- CSS生成动态目录结构:COOLjsMenuPRO组件
- Linux用树形结构显示目录结构
- 使用T-SQL生成树形目录(引用)
- 利用TreeView控件动态生成无限极树形结构(转为了明天)
- 利用JavaScript 动态生成 树形结构
- 【原】根据网站动态目录生成树结构,并用TreeView输出【提供源码下载,有详细注释】
- ASP生成目录树结构
- 在当前目录生成很漂亮的结构树 -- bigtree.bat
- 使用C#中的DirectorySearcher来获得活动目录中的组织结构与用户等信息,并在展示成树形结构(附源代码)
- asp下生成目录树结构的类
- asp下生成目录树结构的类
- Linux用树形结构显示目录结构
- 如何生成像资源管理器一样的树形目录
- windows中树形导出目录结构
- 基于数据库动态生成树形目录
- JSP生成树形目录 的 方法们
- dTree生成的树形目录
- 再谈网站自动生成系统中的树形结构