20 FSO(連載2)

 
20 FSO(連載2)
 
 
由於篇幅較大,因此分爲兩篇!請原諒!
 
 
1、中級操做

既然咱們將文件內的資源讀取出來了,最好再修飾一下下,就像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 ">

<html xmlns="
http://www.w3.org/1999/xhtml ">

<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>

運行結果以下:
 

 
固然,這個還存在一些問題,例如:沒有辦法瀏覽子文件夾、建立子文件夾、刪除文件/文件夾、文件/文件夾的重命名等,我會在後續的博文中和你們一塊兒來研究!
好了,晚安,各位!!!
相關文章
相關標籤/搜索