如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
源码如下:
<?php
header("content-type:text/html;charset=utf-8");
include_once('./getfilesize.php');
date_default_timezone_set('PRC');
function dirtab ($dir)
{
if (!file_exists($dir)) {
echo "目录不存在";
return false;
}
if (!is_dir($dir)) {
echo "不是目录";
return false;
}
$res = opendir($dir);
$str ='';
$num =0;
while (false !== ($filename = readdir($res))) {
$num++;
$file_path = rtrim($dir,'/').'/'.$filename;
$color = $num % 2 == 0 ? '#abcdef': '#fff';
$str .= "<tr bgcolor=".$color.">";
$str .= "<td>".$filename."</td>";
$str .= "<td>".getfilesize(filesize($file_path))."</td>";
$str .= "<td>".(filetype($file_path) == 'dir' ? '目录':'文件') ."</td>";
$str .= "<td>".(date('Y-m-d H:i:s' , filectime($file_path))) ."</td>";
$str .= "<td>".(date('Y-m-d H:i:s' , filemtime($file_path))) ."</td>";
$str .= "<td>".(is_readable($file_path) == 1 ?'YES' : 'NO') ."</td>";
$str .= "</tr>";
}
closedir($res);
return $str;
}
echo "<table border='1' align='center' cellspacing='0'>";
echo "<tr>";
echo "<th>文件名</th>";
echo "<th>文件大小</th>";
echo "<th>类型</th>";
echo "<th>创建时间</th>";
echo "<th>修改时间</th>";
echo "<th>是否可读</th>";
echo "</tr>";
echo dirtab ('../');
echo "</table>";
王明昌博客
