原生php实现遍历目录信息

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> 遍历目录信息 </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="dz5362">
  <meta name="Keywords" content="dz5362">
  <meta name="Description" content="no-description">
  <meta http-equiv="Content-type" content="text/html;charset=GB2312">
   <link rel='stylesheet' type='text/css' href='style.css'>
 </head>

 <body>
 <div id='header'>遍历指定目录信息</div>
 <div id='content'>
  <form method="post" action="cyg.php" id='myForm'>
  <center>请输入目录路径</center>
  <input type='text' name='path' size='25'><br>
  <input type="submit" value='查看' class='input'>
  </form>
  </div>
  <div id='footer'>cyg 2012</div>
 </body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
   <style>
  table{
  border-collapse:collapse;
  border:1px solid #ccc;
  }
  table td{
  border:1px solid #ccc;
  line-height:22px;
  background:#eee;
  }
  </style>
 </head>

 <body>
 <?php
 if($_POST['path']){
  $path_start = $_POST['path']; //获取绝对路径
  $path = opendir($path_start); //打开目录
  ?>
 <center>目录信息如下表所示</center>
  <table border='0' cellspacing='0' cellpadding='0' width='450' align='center'>
  <tr align="left" bgcolor="#cccccc">
    <th>文件名</th><th>大小</th><th>类型</th><th>修改时间</th>
  </tr>
  <?php
    $str = '';
    while($file=readdir($path)){//读取某个目录下的信息
    $dir = $path_start."/".$file;     //获取完整的路径和文件名称
    $str .=  '<tr align=\'center\'>';             
    $str .= '<td>'.$file.'</td>';                     
        $str .= '<td>'.ceil((filesize($dir))/1024).'kb</td>';//获取目录下某个文件的大小
        $str .= '<td>'.(filetype($dir)=='dir'?'文件夹':'文件').'</td>';//看类型是文件还是文件夹
        $str .= '<td>'.date("Y/n/t",filemtime($dir)).'</td>';//查看目录的日期
        $str .= '</tr>';  
  }
  echo $str;
  ?>
  </table>
  <?php
 }
 ?>
</body>
</html>

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贵哥的编程之路(热爱分享)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值