php专区

 首页 > php专区 > PHP应用 > 常用功能 > php+jquery实现无限级目录遍历展示代码 - php高级应

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

分享到:
【字体:
导读:
          这个例子可以利用php目录遍历出来的目录或文件进行一个树型的展示效果,程序代码,index php 里面的jquery文件大家可百度下载一个,因为这是用来实现一个效果的:index php:scriptsrc=jquery jquer...

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

这个例子可以利用php目录遍历出来的目录或文件进行一个树型的展示效果,程序代码,index.php 里面的jquery文件大家可百度下载一个,因为这是用来实现一个效果的:

index.php:

  1. "jquery/jquery-1.3.1.js" type="text/javascript"
  2. "text/css"
  3. body 
  4. {font: normal 12px arial, tahoma, helvetica, sans-serif;margin:0;background:#fff;padding:30px;} 
  5. *{ margin:0; padding:0;} 
  6. ul{ visibility:visible; cursor:pointer;} 
  7. .simpleTree li{font-size:14px; list-style: none;margin:0 0 0 50px;padding:0 0 0 34px;line-height: 18px;margin-left:-13px;background: url(jquery/images/expandable.gif) 0 -2px no-repeat #fff;} 
  8. .simpleTree li span{display:inline;clear: left;white-space: nowrap;} 
  9. li.root{padding:0 0 0 20px;line-height:20px;background: url(jquery/images/root.gif) 0 2px no-repeat #fff;} 
  10. li.file{padding:0 0 0 35px;line-height:20px;background: url(jquery/images/leaf-last.gif) 0 2px no-repeat #fff;} 
  11.  
  12. "text/javascript"
  13. $(function(){ 
  14.  $(".simpleTree").children("li").find("ul").hide(); 
  15. $("span").click(function(){ 
  16.  var $this_ul=$(this).siblings("ul"); 
  17.  if($this_ul.is(":visible")){ 
  18. $this_ul.stop(false,true).hide(); 
  19.  }else
  20. $(this).siblings("ul").stop(false,true).show().end().stop(false,true).siblings("ul").find("ul").hide(); 
  21.  } 
  22. }) 
  23.  
  24. }) 
  25.  
  26. include("function.php"); 
  27. $path="目录/";//目录名 
  28. echo "目录"//目录名,和path 中名称一样 
  29. list_dir($path); 
  30. echo "
  31. "
  32. ?> 

function.php 这个文件包含了遍历目录的函数了,代码如下:

  1. /*输出当前目录下的所有文件数量*/ 
  2. function files_count($path,  & $i=0){ 
  3. if($opendir=opendir($path)){ 
  4. //=============== 
  5. while($file=readdir($opendir) ){ 
  6. if($file!="."&&$file!=".."){ 
  7.  if(is_file($path."/".$file)){ 
  8.   $i++; 
  9.  ; 
  10.  }else
  11.   files_count($path."/".$file$i); 
  12.  } 
  13.  } 
  14. //============= 
  15. return  "(".$i.")"
  16. //echo files_count("目录/目录1/3/"); 
  17. //=============================// 
  18. /*遍历目录*/ 
  19. function list_dir($path){ 
  20. if($opendir=opendir($path)){ 
  21.  
  22. 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 ".$path."/".$file."'>".$file."
    • "
    •   } 
    •   } 
    •  } 
    • echo "
  23. "
  24. ?> 
分享到:
php微信公众平台开发之获取用户基本信息
本文的方法将囊括订阅号和服务号以及自定义菜单各种场景,无论是否有高级接口权限,都有办法来获得用户基本信息,而无需模拟登录。 把微信和第三方网站结合起来运行,是许多客户经常要的方案。这里简要介绍一下获取微信用户的基本信息,并在第三方网站直接登录。 当微信公户关注一个公众号时,会产生一个独一无二的OpenID,...
PHP进程锁类PHPLock程序代码 - php高级应...
PHP进程锁类PHPLock程序代码 为了更好的控制php程序同时操作的一些问题我整理了一个进程锁的类我们可以利用这个进程锁实现程序的控制,程序代码如下:  
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……