国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php+jquery實現(xiàn)無限級目錄遍歷展示代碼

2024-05-04 21:47:45
字體:
供稿:網(wǎng)友

這個例子可以利用php目錄遍歷出來的目錄或文件進行一個樹型的展示效果,程序代碼,index.php 里面的jquery文件大家可百度下載一個,因為這是用來實現(xiàn)一個效果的:

index.php:

  1. <script src="jquery/jquery-1.3.1.js" type="text/javascript"></script> 
  2. <style type="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. </style> 
  12. <script type="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. </script> 
  26. <?php 
  27. include("function.php"); 
  28. $path="目錄/";//目錄名 
  29. echo "<ul class='simpleTree'><li class='root'><span>目錄</span>"//目錄名,和path 中名稱一樣 
  30. list_dir($path); 
  31. echo "</ul></li>"
  32. ?> 

function.php 這個文件包含了遍歷目錄的函數(shù)了,代碼如下:

  1. <?php 
  2. /*輸出當前目錄下的所有文件數(shù)量*/ 
  3. function files_count($path,  & $i=0){ 
  4. if($opendir=opendir($path)){ 
  5. //=============== 
  6. while($file=readdir($opendir) ){ 
  7. if($file!="."&&$file!=".."){ 
  8.  if(is_file($path."/".$file)){ 
  9.   $i++; 
  10.  ; 
  11.  }else
  12.   files_count($path."/".$file$i); 
  13.  } 
  14.  } 
  15. //============= 
  16. return  "(".$i.")"
  17. //echo files_count("目錄/目錄1/3/"); 
  18. //=============================// 
  19. /*遍歷目錄*/ 
  20. function list_dir($path){ 
  21. if($opendir=opendir($path)){ 
  22.  
  23. echo "<ul>"
  24. while($file=readdir($opendir)){ 
  25.  if($file!="."&&$file!=".."){ 
  26.   if(is_dir($path."/".$file)){ 
  27.  
  28. $bar=scandir($path."/".$file); 
  29. unset($bar[0]); 
  30. unset($bar[1]); 
  31. if(count($bar!==0)){ 
  32.  echo "<li><span>".$file.files_count($path."/".$file)."</span>"
  33.  list_dir($path."/".$file); 
  34.  
  35.   }else
  36.    echo "<li class='file'><a  href='".$path."/".$file."'>".$file."</a></li>"
  37.   } 
  38.   } 
  39.  } 
  40. echo "</ul></li>"
  41. ?> 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 略阳县| 贺兰县| 金门县| 阳曲县| 定安县| 揭东县| 东丰县| 东宁县| 宜良县| 石家庄市| 甘谷县| 柯坪县| 沙田区| 柘城县| 雅安市| 湄潭县| 电白县| 漳州市| 白朗县| 青神县| 鄱阳县| 平乡县| 南木林县| 东海县| 织金县| 卓尼县| 台北市| 双柏县| 丰都县| 马龙县| 珠海市| 明溪县| 赣榆县| 延长县| 乐山市| 万荣县| 安宁市| 元阳县| 萨嘎县| 巨鹿县| 通道|