<?php
//引入函数
//修改时区
date_default_timezone_set('PRC');
//将目录的文件名遍历到表格中
echo '<table border="1" width="800" align="center">';
echo '<tr>';
echo '<th>编号</th>';
echo '<th>文件名</th>';
echo '<th>文件大小</th>';
echo '<th>文件类型</th>';
echo '<th>文件创建时间</th>';
echo '<th>文件是否可读</th>';
echo '</tr>';
//打开目录
$handle = opendir('../1225lkd');
//声明一个编号的变量进行累加
$i = 1;
//循环读取文件名
while($filename = readdir($handle)){
//取消掉.和..
if($filename == '.' || $filename =='..'){
continue;//跳出当次循环进入下次循环
}
//拼接一个完成的路径给后面的函数使用
$filepath = '../1225lkd/'.$filename;
echo '<tr>';
echo '<td>'.$i++.'</td>';
echo '<td>'.$filename.'</td>';
echo '<td>'.filesize($filepath).'</td>';
echo '<td>'.filetype($filepath).'</td>';
echo '<td>'.date('Y-m-d H:i:s',filectime($filepath)).'</td>';
echo '<td>'.(is_readable($filepath)?'可读':'不可读').'</td>';
echo '</tr>';
}
echo '</table>';
//关闭目录
closedir($handle);点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号