做文件管理的基础设施建设吧,嗯……反正还是打到打不开的思路来的。
这里为了后续方便,忽略了本目录.
的显示,然后对于根目录不显示上一级的..
$num = 0; // 统计子目录和文件个数
$problem = FALSE;
$fileList = [];
if (!empty($_GET['route']))
$dirname = $_GET['route'];
else
$dirname = 'upload';
$dir_handle = @opendir($dirname);
if (!file_exists($dirname))
echo "<script>window.location.href='"."index.php';</script>";
if (!$problem) {
while ($file = readdir($dir_handle)) {
$dirFile = $dirname.'/'.$file;
if ($dirname == 'upload' && $file != '.' && $file != '..') {
$fileList[$num] = array('file' => $file, 'filesize' => filesize($dirFile), 'filetype' => filetype($dirFile), 'filemtime' => date('Y/n/t',filemtime($dirFile)));
if (is_dir($dirFile)) {
$fileList[$num]['filesize'] = '';
}
$num++;
} elseif ($dirname != 'upload' && $file != '.') {
$fileList[$num] = array('file' => $file, 'filesize' => filesize($dirFile), 'filetype' => filetype($dirFile), 'filemtime' => date('Y/n/t',filemtime($dirFile)));
if (is_dir($dirFile)) {
$fileList[$num]['filesize'] = '';
}
$num++;
}
}
}
/*
// 统计文件夹大小
function dirSize($dir) {
$dir_size = 0;
if ($dirhandle = @opendir($dir)) {
while ($filename = readdir($dirhandle)) {
if ($filename != '.' && $filename != '..') {
$subFile = $dir.'/'.$filename;
if(is_dir($subFile))
$dir_size += dirSize($subFile);
if(is_file($subFile))
$dir_size += filesize($subFile);
}
}
closedir($dirhandle);
echo 'Hello';
return $dir_size;
}
}
*/
@closedir($dir_handle);
return $fileList;