- '; while(($element = readdir($dp)) !== false) { if($element != '.' && $element != '..') { if(is_dir($path.$element)) { list($size_dir,$sub_num_dir,$sub_num_file,$sub_out) = get_dir_size($path.$element); $out .= '
- '.$path.$element.':'; $out .= ''.setupSize($size_dir).',Sub dir:'.$sub_num_dir.',file:'.$sub_num_file.''.$sub_out.'
- '; $size += $size_dir; $num_dir +=$sub_num_dir; $num_file +=$sub_num_file; $num_dir ++;//本文件夹 } else { $size += filesize($path.$element); //不显示文件列表 //echo '
- '.$path.$element.':'. setupSize(filesize($path.$element)).'
- '; $num_file++; } } } $out .= '
'; $size =$fileSize; if($size == 0) { return("0 Bytes"); } $sizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizename[$i]; } header('Content-type:text/html;Charset=utf-8'); //取出来的是字节,所以还要除以1024*1024,然后用number_format()四舍五入取两位小数 //就是这里造成了windows资源管理器中文件夹大小不一致的原因,因为后者是直接截取2位 //E:\WebsiteData\200MB\sundayschool-CCFIILPSSVZZdggjnnqtww1447AAEHHK\www $full_use_space=1073741824*20;//可使用空间大小G $path = dirname(__FILE__); //$path =substr($path,0,-11); //$size = get_dir_size($path); list($size,$num_dir,$num_file,$out)= get_dir_size($path); //echo $path.$dir; //echo $size.' Bytes'; ?>
可使用空间大小:'; echo setupSize($full_use_space);
echo ‘
已经使用空间大小:’;
echo setupSize($size);
echo ‘
剩余空间大小:’;
$can_use_size = $full_use_space - $size;
echo
c
a
n
u
s
e
s
i
z
e
<
0
?
′
−
′
:
′
′
;
e
c
h
o
s
e
t
u
p
S
i
z
e
(
a
b
s
(
can_use_size < 0 ? '-':''; echo setupSize(abs(
canusesize<0?′−′:′′;echosetupSize(abs(can_use_size));
echo ‘
总目录数:’;
echo $num_dir;
echo ‘
总文件数:’;
echo $num_file;
echo ‘
’;
echo $out;
//echo ‘
’;
//echo number_format($size /1024/1024, 2) , ‘M’;
?>