php 文件大小格式化
忘了出处是哪儿 ,实现很巧妙
function filesize_formatted($path) { $size = filesize($path); $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); $power = $size > 0 ? floor(log($size, 1024)) : 0; return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power]; }