免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2241 | 回复: 1
打印 上一主题 下一主题

在线查阅文件系统列表 look file system on line [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-11 16:39 |只看该作者 |倒序浏览

  1. <?php
  2. /*********************************************************************************************************************
  3. * 功能:获取指定文件列表,为file_show.php做准备                                                                        *
  4. * 作者:张树林              Author:woods.zhang              日期:2005-11-11                Date:2005-11-11            *
  5. * 版本:1.0.0               Version:1.0.0                   Email:hoojar@163.com           QQ:37894354                *
  6. * MSN:hoojar@hotmail.com                                   网站地址:http://hoojar.com/                               *
  7. *********************************************************************************************************************/
  8. ?>
  9. <html>
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  12. <meta http-equiv="keyword" content="* 在线查阅文件系统列表 look file system on line            *">
  13. <meta http-equiv="keyword" content="* 作者:张树林              Author:woods.zhang              日期:2005-11-11                Date:2005-11-11            *">
  14. <meta http-equiv="keyword" content="* 版本:1.0.0               Version:1.0.0                   Email:hoojar@163.com           QQ:37894354                *">
  15. <meta http-equiv="keyword" content="* MSN:hoojar@hotmail.com                                   网站地址:http://hoojar.com/                               *">
  16. <title>获取文件列表</title>
  17. <script language="javascript">
  18. <!--
  19. function TreeOnOff(nu, path)
  20. {
  21.     eval("var ob = folder" + nu + ".style");
  22.     eval("var TE = TreeExpand" + nu);
  23.     eval("var TI = TreeIcon" + nu);
  24.     if (ob.display == "none")
  25.     {
  26.         top.main.location = "./file_show.php?folder=" + path;
  27.         TE.src = "./images/M1.gif";
  28.         TI.src = "./images/folderopen.gif";
  29.         ob.display = "block";
  30.     }
  31.     else
  32.     {
  33.         TE.src = "./images/P1.gif";
  34.         TI.src = "./images/small_folder.gif";
  35.         ob.display = "none";
  36.         top.main.location = "./file_show.php?folder=|woodshoojar|";
  37.     }
  38. }
  39. //-->
  40. </script>
  41. </head>
  42. <body>
  43. <?php
  44. function folder_list($nu, $level, $path, $dp)
  45. /* 功能:文件夹组合  */
  46. {
  47. return <<< EOT
  48.     <div noWrap onclick="TreeOnOff({$nu}, '{$path}')" style="CURSOR: hand; width: 50px">
  49.         <nobr>{$level}<img id="TreeExpand{$nu}" src="./images/P1.gif" align="absMiddle"><img id="TreeIcon{$nu}" src="./images/small_folder.gif" align="absMiddle">&nbsp;{$dp}</nobr>
  50.     </div>
  51. <span id="folder{$nu}" style="display:none">
  52. EOT;
  53. }

  54. function file_list($level, $path, $dp)
  55. /* 功能:文件组合  */
  56. {
  57. return <<< EOT
  58. <div noWrap style="width: 50px">
  59.     <nobr>
  60.         {$level}<img src="./images/L1.gif" align="absMiddle"><img src="./images/file.gif" align="absMiddle">&nbsp;{$dp}
  61.     </nobr>
  62. </div>

  63. EOT;
  64. }

  65. /*********************************************************************
  66. 功能:主要用来管理文件系统
  67. 参数:$root_dir为要操作的文件夹
  68.       $file_type = "*"显示哪种类型文件
  69.       $r = false 是否递归子文件夹
  70.       $f = false 是否列表文件
  71. 作者:张树林
  72. 日期:2005-11-11
  73. *********************************************************************/
  74. function list_file($root_dir, $file_type = "*", $r = false, $f = false)
  75. {
  76.     #_____列出指定目录中所有指定要显示的文件类型___________
  77.     static $nu;
  78.     global $list_file;
  79.     #___取要搜索的路径中最后一个字符是否为/_________
  80.     $last_is = $root_dir{strlen($root_dir)-1};
  81.     if ($last_is != "/")
  82.     {
  83.         $root_dir = $root_dir."/";
  84.     }
  85.     if (!is_dir($root_dir))
  86.     #_________如果获取的不是文件夹则退出____
  87.     {
  88.         return false;
  89.     }

  90.     $folder = opendir($root_dir);
  91.     while (($dp = readdir($folder)) !== false)
  92.     {
  93.         if ($dp == "." || $dp == "..")
  94.         #___________排除.或..的文件夹_______
  95.         {
  96.             continue;
  97.         }

  98.         /*____________________此处为等级,分列子目录前有多少个列线___________________begin________*/
  99.         $level = "";
  100.         $rank = substr_count($root_dir.$dp, "/");
  101.         for ($i = 1; $i < $rank; $i++)
  102.         {
  103.             $level .= '<img height="20" src="./images/L4.gif" align="absMiddle">';
  104.         }
  105.         /*____________________此处为等级,分列子目录前有多少个列线___________________end________*/

  106.         if (is_dir($root_dir.$dp))
  107.         {
  108.         //________递归操作____________
  109.             if ($r)
  110.             {
  111.                 $nu++;
  112.                 $list_file .= folder_list($nu, $level, base64_encode($root_dir.$dp."/"), $dp); //"<div noWrap onclick="TreeOnOff({$nu})" style="CURSOR: hand; width: 50px">n        <nobr>{$level}<img id="TreeExpand{$nu}" src="./images/P1.gif" align="absMiddle"><img id="TreeIcon{$nu}" src="./images/folder.gif" align="absMiddle">{$dp}</nobr>n    </div>n<span id="folder{$nu}" style="display:none">n";
  113.                 list_file($root_dir.$dp."/", $file_type, $r);
  114.             }
  115.             continue;
  116.         }

  117.         if (!$f)//判断是否要列表文件
  118.         {
  119.             continue;
  120.         }

  121.         $is_list = false;
  122.         #______如果没有扩展名就显示所有文件_________
  123.         if ($file_type == "*" || $file_type == "")
  124.         {
  125.             $is_list = true;
  126.         }
  127.         else
  128.         {
  129.             #_______分解要处理的文件类型扩展名__________
  130.             $file_type = strtolower($file_type);#___转换成小写的扩展名
  131.             $ext = explode("|",$file_type);
  132.             #__________例出符合条件的文件类型____循环文件类型________
  133.             for ($i = 0;$i < count($ext);$i++)
  134.             {
  135.                 #__________获取文件的扩展名,来判断所属类型
  136.                 $file_info = pathinfo($dp);
  137.                 $get_ext = $file_info["extension"];
  138.                 $get_ext = strtolower($get_ext);#___转换成小写的扩展名
  139.                 if ($get_ext == $ext[$i])
  140.                 {
  141.                     $is_list = true;
  142.                     break;#_____跳出本次文件扩展名的循环____________
  143.                 } //end if
  144.             } //end for $i
  145.         }

  146.         if ($is_list)
  147.         {
  148.             $list_file .= file_list($level, base64_encode($root_dir), $dp);// "<div noWrap style="width: 50px">n    <nobr>n        {$level}<img src="./images/L1.gif" align="absMiddle"><img src="./images/file.gif" align="absMiddle">{$dp}n    </nobr>n</div>n";
  149.         }
  150.     } //end while
  151.     $list_file .= '</span>';
  152.     closedir($folder);//关闭文件夹句枘
  153. }

  154. $folder = "../";
  155. $bfolder = base64_encode($folder);
  156. $list_file = "<a href="./file_show.php?folder={$bfolder}" target="main"><img src="./images/home.gif" align="absMiddle" border="0"></a>n";
  157. list_file($folder, "*", true);
  158. echo($list_file. '<img src="./images/hoojar.gif" align="absMiddle">');
  159. ?>
  160. </body>
  161. </html>
复制代码

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
2 [报告]
发表于 2005-11-11 17:51 |只看该作者
http://www.moment.com.cn/Album.php

一个很简单的图片列表,直接读取目录何文件的,使用http://www.smartphp.net的目录组件
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP