PHP实现的文件浏览器功能简单示例

时间:2022-09-23 19:40:51

本文实例讲述了PHP实现的文件浏览器功能。分享给大家供大家参考,具体如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?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程序设计有所帮助。

原文链接:https://blog.csdn.net/koastal/article/details/50274087