[PHP文件管理器]②--列表顯示文件類型 大小

Paste_Image.png
Paste_Image.png

file.func.php

<?php
/**
 * 轉化字節大小
 * @param number $size
 * @return number
 */
function transByte($size) {
    // Bytes/KB/MB/GB/TB/EB
    $arr = array (
            "B",
            "KB",
            "MB",
            "GB",
            "TB",
            "TB" 
    );
    $i = 0;
    while ( $size > 1024 ) {
        $size /= 1024;
        $i ++;
    }
    return round ( $size, 2 ) . $arr [$i];
}
?>

index.php

<?php
require_once ('dir.func.php');
require_once 'file.func.php';
$path = 'file';
$arr = readDirectory ( $path );

?>

<!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=UTF-8" />
<title>Insert title here</title>
<link rel="stylesheet" href="cikonss.css" />
<script src="jquery-ui/js/jquery-1.10.2.js"></script>
<script src="jquery-ui/js/jquery-ui-1.10.4.custom.js"></script>
<script src="jquery-ui/js/jquery-ui-1.10.4.custom.min.js"></script>
<link rel="stylesheet"
    href="jquery-ui/css/ui-lightness/jquery-ui-1.10.4.custom.css"
    type="text/css" />
<style type="text/css">
body,p,div,ul,ol,table,dl,dd,dt {
    margin: 0;
    padding: 0;
}

a {
    text-decoration: none;
}

ul,li {
    list-style: none;
    float: left;
}

#top {
    width: 100%;
    height: 48px;
    margin: 0 auto;
    background: #E2E2E2;
}

#navi a {
    display: block;
    width: 48px;
    height: 48px;
}

#main {
    margin: 0 auto;
    border: 2px solid #ABCDEF;
}

.small {
    width: 25px;
    height: 25px;
    border: 0;
}
</style>
<script type="text/javascript">
    function show(dis){
    document.getElementById(dis).style.display="block";
    }
    function delFile(filename,path){
        if(window.confirm("您確定要刪除嘛?刪除之后無法恢復喲!!!")){
                location.href="index.php?act=delFile&filename="+filename+"&path="+path;
        }
    }
    function delFolder(dirname,path){
        if(window.confirm("您確定要刪除嘛?刪除之后無法恢復喲!!!")){
            location.href="index.php?act=delFolder&dirname="+dirname+"&path="+path;
        }
    }
    function showDetail(t,filename){
        $("#showImg").attr("src",filename);
        $("#showDetail").dialog({
              height:"auto",
              width: "auto",
              position: {my: "center", at: "center",  collision:"fit"},
              modal:false,//是否模式對話框
              draggable:true,//是否允許拖拽
              resizable:true,//是否允許拖動
              title:t,//對話框標題
              show:"slide",
              hide:"explode"
        });
        }
    function goBack($back){
        location.href="index.php?path="+$back;
    }
</script>
</head>

<body>
    <div id="showDetail" style="display: none">
        <img src="" id="showImg" alt="" />
    </div>
    <h1>慕課網-在線文件管理器</h1>
    <div id="top">
        <ul id="navi">
            <li><a href="index.php" title="主目錄"><span
                    style="margin-left: 8px; margin-top: 0px; top: 4px;"
                    class="icon icon-small icon-square"><span class="icon-home"></span></span></a></li>
            <li><a href="#" onclick="show('createFile')" title="新建文件"><span
                    style="margin-left: 8px; margin-top: 0px; top: 4px;"
                    class="icon icon-small icon-square"><span class="icon-file"></span></span></a></li>
            <li><a href="#" onclick="show('createFolder')" title="新建文件夾"><span
                    style="margin-left: 8px; margin-top: 0px; top: 4px;"
                    class="icon icon-small icon-square"><span class="icon-folder"></span></span></a></li>
            <li><a href="#" onclick="show('uploadFile')" title="上傳文件"><span
                    style="margin-left: 8px; margin-top: 0px; top: 4px;"
                    class="icon icon-small icon-square"><span class="icon-upload"></span></span></a></li>

            <li><a href="#" title="返回上級目錄" onclick="goBack('')"><span
                    style="margin-left: 8px; margin-top: 0px; top: 4px;"
                    class="icon icon-small icon-square"><span class="icon-arrowLeft"></span></span></a></li>
        </ul>
    </div>
    <table width="100%" border="1" cellpadding="5" cellspacing="0"
        bgcolor="#ABCDEF" align="center">
        <tr>
            <td>編號</td>
            <td>名稱</td>
            <td>類型</td>
            <td>大小</td>
            <td>可讀</td>
            <td>可寫</td>
            <td>可執行</td>
            <td>創建時間</td>
            <td>修改時間</td>
            <td>訪問時間</td>
            <td>操作</td>
        </tr>
        <?php
        if ($arr ['file']) {
            $i = 1;
            foreach ( $arr ['file'] as $val ) {
                $p = $path . "/" . $val;
                ?>
            <tr>
            <td><?php echo $i;?></td>
            <td><?php echo $val;?></td>
            <td><?php $src=filetype($p)=='file'?"file_ico.png":"folder_ico.png";?>
                <img src="images/<?php echo $src;?>" alt="" title="文件" /></td>
            <td><?php echo transByte(filesize($p));?></td>
        </tr>
            
            
        <?php
                $i ++;
            }
        }
        ?>
    </table>
</body>
</html>
Paste_Image.png
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容