当前位置:首页 > PHP教程 > php文件操作 > 列表

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

发布:smiling 来源: PHP粉丝网  添加日期:2021-12-17 11:43:08 浏览: 评论:0 

这篇文章主要介绍了PHP实现的文件浏览器功能,结合完整实例形式分析了php针对目录与文件的遍历、判断、属性读取等相关操作技巧,需要的朋友可以参考下。

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

  1. <?php 
  2. if(isset($_GET['path'])){ 
  3.   echo $path = $_SERVER['DOCUMENT_ROOT'].$_GET['path']; 
  4.   $pre_path = $_GET['path']; 
  5. }else{ 
  6.   echo $path = $_SERVER['DOCUMENT_ROOT']; 
  7.   $pre_path = ""; 
  8. } 
  9. ?> 
  10. <html> 
  11.   <head> 
  12.     <title></title> 
  13.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
  14.   </head> 
  15.   <body> 
  16.     <table border="1"> 
  17.       <thead> 
  18.         <tr> 
  19.           <td>文件名</td> 
  20.           <td>文件大小</td> 
  21.           <td>文件类型</td> 
  22.           <td>修改时间</td> 
  23.         </tr> 
  24.       <thead> 
  25.       <tbody> 
  26.         <?php 
  27.         $url_this = "http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF']; 
  28.         $handle = opendir($path); 
  29.         while($file=readdir($handle)){ 
  30.           echo "<tr>"; 
  31.           echo "<td>".$file."</td>"; 
  32.           echo "<td>".filesize($path."/".$file)."</td>"; 
  33.           if(filetype($path."/".$file)=="dir"){ 
  34.             $next = $pre_path."/".$file; 
  35.             echo "<td><a href=\"$url_this?path=$next\">dir</a></td>"; 
  36.           }else{ 
  37.             echo "<td>".filetype($path."/".$file)."</td>"; 
  38.           } 
  39.           echo "<td>".date("Y年n月t日",filemtime($path."/".$file))."</td>"; 
  40.           echo "</tr>"; 
  41.         } 
  42.         closedir($handle); 
  43.         ?> 
  44.       </tbody> 
  45.     </table> 
  46.   </body> 
  47. </body>

Tags: PHP文件浏览器

分享到: