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);
static $str ='';//如果不使用static,那么只输出一层,下一层的目录内容不输出
$num =0;
while (false !== ($filename = readdir($res))) {
$num++;
$file_path = rtrim($dir,'/').'/'.$filename;
if($filename == '.' || $filename == '..'){
continue;
}
if(is_dir($file_path)){
dirtab($file_path);
}
$color = $num % 2 == 0 ? '#abcdef': '#fff';
$str .= "
";$str .= "
".$filename."";$str .= "
".getfilesize(filesize($file_path))."";$str .= "
".(filetype($file_path) == 'dir' ? '目录':'文件') ."";$str .= "
".(date('Y-m-d H:i:s' , filectime($file_path))) ."";$str .= "
".(date('Y-m-d H:i:s' , filemtime($file_path))) ."";$str .= "
".(is_readable($file_path) == 1 ?'YES' : 'NO') ."";$str .= "
";}
closedir($res);
return $str;
}
echo "
echo "
";echo "
文件名";echo "
文件大小";echo "
类型";echo "
创建时间";echo "
修改时间";echo "
是否可读";echo "
";echo dirtab ('../1127');
echo "
";