原生php实现遍历目录信息
【摘要】
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dt...
<!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>
- 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
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
文章来源: blog.csdn.net,作者:贵哥的编程之路(热爱分享),版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_37805832/article/details/123804475
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)