经测试代码如下:
<?PHP
/**
* 文件大小转换成KB,MB,GB,TB等单位
*
* @param
* @arrange (512.笔记) jb51.cc
**/
function ByteSize ( $file_size )
{
$file_size = $file_size-1;
if ($file_size >= 1099511627776) $show_filesize = number_format(($file_size / 1099511627776),2) . " TB";
elseif ($file_size >= 1073741824) $show_filesize = number_format(($file_size / 1073741824),2) . " GB";
elseif ($file_size >= 1048576) $show_filesize = number_format(($file_size / 1048576),2) . " MB";
elseif ($file_size >= 1024) $show_filesize = number_format(($file_size / 1024),2) . " KB";
elseif ($file_size > 0) $show_filesize = $file_size . " b";
elseif ($file_size == 0 || $file_size == -1) $show_filesize = "0 b";
return $show_filesize;
}
/*** 来自:编程之家 jb51.cc(jb51.cc) ***/
?>
原文链接:https://www.f2er.com/php/528798.html