<?PHPEcho' <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> ';functionTraverse$path,$x,$y) { $current _dir=Opendir($path); while(($file=Readdir($current _dir)) !==false) { $sub _dir=$path. Directory_separator.$file;//To build a subdirectory path 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;functionTraverse2 ($path,$x,$y) { Global $countFile; $current _dir=Opendir($path); while(($file=Readdir($current _dir)) !==false) { $sub _dir=$path. Directory_separator.$file;//To build a subdirectory path 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 (); ' > All folds </button><button onclick= ' $ (\ ". expandable\"). Children (). Show (); ' > Expand All </button></div> ";Echo"<ul style= ' position:relative; ' > "; Traverse2 ('. ', 0, 0);Echo"</ul>";Echo"<p style= ' clear:both;position:relative ' > Total".$countFile. "File </p>";//Traverse (".", 0, 0);?>
Generate a directory tree structure