本文实例讲述了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相关内容感兴趣的读者可查看jb51专题:《php文件操作总结》、《PHP目录操作技巧汇总》、《PHP常用遍历算法与技巧总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》及《PHP网络编程技巧总结》
希望本文所述对大家PHP程序设计有所帮助。