标签:
<?php echo ‘<script src="http://code.jquery.com/jquery.min.js"></script>‘; echo ‘<script>$(function(){$(".expandable").click(function(){event.preventDefault();event.stopPropagation();$(this).children().toggle();});$(".file").click(function(){event.stopPropagation();event.preventDefault();});});</script>‘; echo ‘<style>.expandable{cursor:pointer;}.file{color:purple;}</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 "<div id=‘control‘><button onclick=‘$(\".expandable\").children().hide();‘>全部折叠</button><button onclick=‘$(\".expandable\").children().show();‘>全部展开</button></div>"; echo "<ul style=‘position:relative;‘>"; traverse2(‘.‘, 0, 0); echo "</ul>"; echo "<p style=‘clear:both;position:relative‘>共计" . $countFile . "个文件</p>"; // traverse(".", 0, 0); ?>
标签:
原文地址:http://www.cnblogs.com/sky-view/p/4421735.html