您当前的位置: 首页 >  php

暂无认证

  • 4浏览

    0关注

    95081博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

原生php实现遍历目录信息

发布时间:2022-03-28 20:11:37 ,浏览量:4

<!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 .= ''; $str .= ''.$file.''; $str .= ''.ceil((filesize($dir))/1024).'kb';//获取目录下某个文件的大小 $str .= ''.(filetype($dir)=='dir'?'文件夹':'文件').'';//看类型是文件还是文件夹 $str .= ''.date("Y/n/t",filemtime($dir)).'';//查看目录的日期 $str .= ''; } echo $str; ?> </table> <?php } ?> </body> </html> 

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

关注
打赏
1655516835
查看更多评论
立即登录/注册

微信扫码登录

0.0533s