20 FSO(连载2)
 
 
因为篇幅较大,所以分为两篇!请原谅!
 
 
一、中级操作

既然我们将文件内的资源读取出来了,最好再修饰一下下,就像Windows的资源管理器一样最好了!(唉,人的欲望总是无限膨胀的!哈哈,这样也好!人类也就是这样才进步的!)

代码如下:

 
<?php
 
date_default_timezone_set("PRC");
 
$filetype_array = array("as"=>"Flash ActionScript File","bmp"=>"BMP图像","doc"=>"Microsoft Word文档","rar"=>"WinRAR 压缩文档","ppt"=>"Microsoft PowerPoint 演示文稿","txt"=>"文本文档","xls"=>"Microsoft Excel 工作表","gif"=>"GIF图像","jpg"=>"JPEG图像","jpeg"=>"JPEG图像","png"=>"PNG图像","html"=>"HTML Document","htm"=>"HTML Document","mp3"=>"MP3 格式声音","chm"=>"已编译的HTML帮助文件","fla"=>"Flash Document","mdb"=>"Microsoft Access 应用程序","pdf"=>"PDF 文件","swf"=>"Flash Movie","xml"=>"XML 文档","zip"=>"WinRAR ZIP 压缩文件","asf"=>"Windows 音频/视频文件","wmv"=>"Windows Media 音频/视频文件","avi"=>"视频剪辑","mpeg"=>"电影剪辑","exe"=>"应用程序","gz"=>"WinRAR 压缩文件","tar"=>"WinRAR 压缩文件","tiff"=>"TIFF 文件");
 
function getobjectsize($object)
 
{
 
$objectsize = filesize($object);
 
if($objectsize < 1024)
 
$objectsize = $objectsize . "&nbsp;B";
 
elseif($objectsize >= 1024 && $objectsize < 1024*1024)
 
$objectsize = ceil($objectsize/1024) . "&nbsp;KB";
 
elseif ($objectsize >= 1024*1024  && $objectsize < 1024*1024*1024)
 
$objectsize = ceil($objectsize/(1024*1024)) . "&nbsp;MB";
 
else
 
$objectsize = ceil($objectsize/(1024*1024*1024)) . "&nbsp;GB";
 
 return $objectsize;
 
}
 
function getobjectmtime($object)
 
{
 
$objectmtime = fileatime($object);
 
return date("Y-m-d H:i",$objectmtime);
 
}
 
function getextensioname($object)
 
{
 
$file_array = split("[.]",$object);
 
$extensioname = strtolower(end($file_array));
 
return $extensioname;
 
}
 
function getobjectype($object)
 
{
 
global $filetype_array;
 
$extensioname = getextensioname($object);
 
if(is_file($object))
 
return $filetype_array[$extensioname];
 
elseif (is_dir($object))
 
return "文件夹";
 
else
 
return "未知类型";
 
}
 
function getIcon($object)
 
{
 
global $$filetype_array;
 
if(is_file($object))
 
$icon = getextensioname($object) . ".gif";
 
 elseif (is_dir($object))
 
$icon = "dir.gif";
 
else
 
$icon = "unknown.gif";
 
return $icon;
 
   
}
 
?>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>目录浏览</title>

<link href="style/common.css" rel="stylesheet" type="text/css" media="all" />

</head>

<body>

<div id="container">

<h1 id="title">目录浏览</h1>

 <div id="location">

 <table border="0" cellspacing="0" cellpadding="0">
 <tr style="background:#ccc">

 <th id="goBack"><a href="#">返回上一级</a></th>

 <th>当前目录:</th>

 <th id="documentRoot">WEB主目录:<?=$_SERVER['DOCUMENT_ROOT']?> </th>

 </tr>

 </table>

 </div>

 <table border="0" cellspacing="0" cellpadding="0" id="itemList">

 <tr>

 <td>名称</td>
 
 <td class="size">大小</td>

 <td class="type">类型</td>

 <td class="type">修改日期</td>

 </tr>
 
 <?php
 
 $folderPath = "./WEB";
 
$folderHandle = opendir($folderPath);
 
while($folderItemName = readdir($folderHandle))
 
{
 
if($folderItemName != "." && $folderItemName != "..")
 
{      
        
$folderItemPath = $folderPath . "/" . $folderItemName;
 
echo("<tr>\n");
 
echo("<td><img src=\"icons/".getIcon($folderItemPath)."\" alt=\"\" align=\"absmiddle\"/>&nbsp;&nbsp;{$folderItemName}</td>\n");
 
echo("<td>".getobjectsize($folderItemPath)."</td>\n");
 
echo("<td>".getobjectype($folderItemPath)."</td>\n");
 
echo("<td>".getobjectmtime($folderItemPath)."</td>\n");  
            
echo("</tr>\n");
 
}
 
}
 
closedir($folderHandle);
   
?>
   
 
 
</table>

</div>

</body>

</html>

运行结果如下:
 
20 FSO(连载2)_PHP

 
当然,这个还存在一些问题,例如:没有办法浏览子文件夹、创建子文件夹、删除文件/文件夹、文件/文件夹的重命名等,我会在后续的博文中和大家一起来研究!

好了,晚安,各位!!!