- 论坛徽章:
- 0
|
- <?php
- /*********************************************************************************************************************
- * 功能:获取指定文件列表,为file_show.php做准备 *
- * 作者:张树林 Author:woods.zhang 日期:2005-11-11 Date:2005-11-11 *
- * 版本:1.0.0 Version:1.0.0 Email:hoojar@163.com QQ:37894354 *
- * MSN:hoojar@hotmail.com 网站地址:http://hoojar.com/ *
- *********************************************************************************************************************/
- ?>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <meta http-equiv="keyword" content="* 在线查阅文件系统列表 look file system on line *">
- <meta http-equiv="keyword" content="* 作者:张树林 Author:woods.zhang 日期:2005-11-11 Date:2005-11-11 *">
- <meta http-equiv="keyword" content="* 版本:1.0.0 Version:1.0.0 Email:hoojar@163.com QQ:37894354 *">
- <meta http-equiv="keyword" content="* MSN:hoojar@hotmail.com 网站地址:http://hoojar.com/ *">
- <title>获取文件列表</title>
- <script language="javascript">
- <!--
- function TreeOnOff(nu, path)
- {
- eval("var ob = folder" + nu + ".style");
- eval("var TE = TreeExpand" + nu);
- eval("var TI = TreeIcon" + nu);
- if (ob.display == "none")
- {
- top.main.location = "./file_show.php?folder=" + path;
- TE.src = "./images/M1.gif";
- TI.src = "./images/folderopen.gif";
- ob.display = "block";
- }
- else
- {
- TE.src = "./images/P1.gif";
- TI.src = "./images/small_folder.gif";
- ob.display = "none";
- top.main.location = "./file_show.php?folder=|woodshoojar|";
- }
- }
- //-->
- </script>
- </head>
- <body>
- <?php
- function folder_list($nu, $level, $path, $dp)
- /* 功能:文件夹组合 */
- {
- return <<< EOT
- <div noWrap onclick="TreeOnOff({$nu}, '{$path}')" style="CURSOR: hand; width: 50px">
- <nobr>{$level}<img id="TreeExpand{$nu}" src="./images/P1.gif" align="absMiddle"><img id="TreeIcon{$nu}" src="./images/small_folder.gif" align="absMiddle"> {$dp}</nobr>
- </div>
- <span id="folder{$nu}" style="display:none">
- EOT;
- }
- function file_list($level, $path, $dp)
- /* 功能:文件组合 */
- {
- return <<< EOT
- <div noWrap style="width: 50px">
- <nobr>
- {$level}<img src="./images/L1.gif" align="absMiddle"><img src="./images/file.gif" align="absMiddle"> {$dp}
- </nobr>
- </div>
- EOT;
- }
- /*********************************************************************
- 功能:主要用来管理文件系统
- 参数:$root_dir为要操作的文件夹
- $file_type = "*"显示哪种类型文件
- $r = false 是否递归子文件夹
- $f = false 是否列表文件
- 作者:张树林
- 日期:2005-11-11
- *********************************************************************/
- function list_file($root_dir, $file_type = "*", $r = false, $f = false)
- {
- #_____列出指定目录中所有指定要显示的文件类型___________
- static $nu;
- global $list_file;
- #___取要搜索的路径中最后一个字符是否为/_________
- $last_is = $root_dir{strlen($root_dir)-1};
- if ($last_is != "/")
- {
- $root_dir = $root_dir."/";
- }
- if (!is_dir($root_dir))
- #_________如果获取的不是文件夹则退出____
- {
- return false;
- }
- $folder = opendir($root_dir);
- while (($dp = readdir($folder)) !== false)
- {
- if ($dp == "." || $dp == "..")
- #___________排除.或..的文件夹_______
- {
- continue;
- }
- /*____________________此处为等级,分列子目录前有多少个列线___________________begin________*/
- $level = "";
- $rank = substr_count($root_dir.$dp, "/");
- for ($i = 1; $i < $rank; $i++)
- {
- $level .= '<img height="20" src="./images/L4.gif" align="absMiddle">';
- }
- /*____________________此处为等级,分列子目录前有多少个列线___________________end________*/
- if (is_dir($root_dir.$dp))
- {
- //________递归操作____________
- if ($r)
- {
- $nu++;
- $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";
- list_file($root_dir.$dp."/", $file_type, $r);
- }
- continue;
- }
- if (!$f)//判断是否要列表文件
- {
- continue;
- }
- $is_list = false;
- #______如果没有扩展名就显示所有文件_________
- if ($file_type == "*" || $file_type == "")
- {
- $is_list = true;
- }
- else
- {
- #_______分解要处理的文件类型扩展名__________
- $file_type = strtolower($file_type);#___转换成小写的扩展名
- $ext = explode("|",$file_type);
- #__________例出符合条件的文件类型____循环文件类型________
- for ($i = 0;$i < count($ext);$i++)
- {
- #__________获取文件的扩展名,来判断所属类型
- $file_info = pathinfo($dp);
- $get_ext = $file_info["extension"];
- $get_ext = strtolower($get_ext);#___转换成小写的扩展名
- if ($get_ext == $ext[$i])
- {
- $is_list = true;
- break;#_____跳出本次文件扩展名的循环____________
- } //end if
- } //end for $i
- }
- if ($is_list)
- {
- $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";
- }
- } //end while
- $list_file .= '</span>';
- closedir($folder);//关闭文件夹句枘
- }
- $folder = "../";
- $bfolder = base64_encode($folder);
- $list_file = "<a href="./file_show.php?folder={$bfolder}" target="main"><img src="./images/home.gif" align="absMiddle" border="0"></a>n";
- list_file($folder, "*", true);
- echo($list_file. '<img src="./images/hoojar.gif" align="absMiddle">');
- ?>
- </body>
- </html>
复制代码 |
|