PHP功能函数----获取文件大小并格式化
这类函数可以让PHP获取文件大小并格式化
function formatSize($size) {
$sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
if ($size == 0) {
return('n/a');
} else {
return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]);
}
}
使用
$thefile = filesize('test_file.mp3');
echo formatSize($thefile);

浙公网安备 33010602011771号