Home > php教程 > PHP源码 > body text

php+jquery实现无限级目录遍历展示代码

WBOY
Release: 2016-06-08 17:21:57
Original
1156 people have browsed it

前面有讲过一个目录遍历的例子,这个例子有一点不一样他可以利用php目录遍历出来的目录或文件进行一个树型的展示效果。

<script>ec(2);</script>

遍历出来的效果如下

php+jquery实现无限级目录遍历展示代码

程序代码


index.php 里面的jquery文件大家可百度下载一个,因为这是用来实现一个效果的

 代码如下 复制代码



 $(".simpleTree").children("li").find("ul").hide();
$("span").click(function(){
 var $this_ul=$(this).siblings("ul");
 if($this_ul.is(":visible")){
$this_ul.stop(false,true).hide();

 }else{
$(this).siblings("ul").stop(false,true).show().end().stop(false,true).siblings("ul").find("ul").hide();
 }

})


})


include("function.php");

$path="目录/";//目录名
echo "

  • 目录"; //目录名,和path 中名称一样
    list_dir($path);

    echo "

";
?>

function.php 这个文件包含了遍历目录的函数了

 代码如下 复制代码

/*输出当前目录下的所有文件数量*/
function files_count($path,  & $i=0){
if($opendir=opendir($path)){
//===============
while($file=readdir($opendir) ){
if($file!="."&&$file!=".."){
 if(is_file($path."/".$file)){
  $i++;
 ;
 }else{

  files_count($path."/".$file, $i);
 }

 }

}

//=============
return  "(".$i.")";
}

}

//echo files_count("目录/目录1/3/");

//=============================//
/*遍历目录*/
function list_dir($path){
if($opendir=opendir($path)){


}
echo "

    ";
    while($file=readdir($opendir)){
     if($file!="."&&$file!=".."){

      if(is_dir($path."/".$file)){

     

    $bar=scandir($path."/".$file);
    unset($bar[0]);
    unset($bar[1]);
    if(count($bar!==0)){
     echo "

  • ".$file.files_count($path."/".$file)."";
     list_dir($path."/".$file);
    }


      }else{

       echo "

  • ".$file."
  • ";
      }

      }

     }
    echo "

";
}
?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!