PHP 文件浏览器

<?php 
if(isset($_GET['path'])){
    echo $path = $_SERVER['DOCUMENT_ROOT'].$_GET['path'];
    $pre_path = $_GET['path'];
}else{
   echo $path = $_SERVER['DOCUMENT_ROOT'];
   $pre_path = "";
}
?>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
    <body>
        <table border="1">
            <thead>
                <tr>
                    <td>文件名</td>
                    <td>文件大小</td>
                    <td>文件类型</td>
                    <td>修改时间</td>
                </tr>
            <thead>
            <tbody>
                <?php
                $url_this = "http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'];
                $handle =  opendir($path);
                while($file=readdir($handle)){
                    echo "<tr>";
                    echo "<td>".$file."</td>";
                    echo "<td>".filesize($path."/".$file)."</td>";
                    if(filetype($path."/".$file)=="dir"){
                        $next = $pre_path."/".$file;
                        echo "<td><a href=\"$url_this?path=$next\">dir</a></td>";
                    }else{
                        echo "<td>".filetype($path."/".$file)."</td>";                        
                    }
                    echo "<td>".date("Y年n月t日",filemtime($path."/".$file))."</td>";
                    echo "</tr>";
                }
                closedir($handle);
                ?>
            </tbody>
        </table>
    </body>
</body>

你可能感兴趣的:(PHP 文件浏览器)