Home >php教程 >php手册 >最快方法计算文件大小,输出' B', ' KB'

最快方法计算文件大小,输出' B', ' KB'

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 19:35:131005browse

目前为止,发现可能是最快的计算方法 是不是还有更快的呢? PHP ?phpdate_default_timezone_set('UTC');function format_bytes($size){ $arr = array(' B', ' KB', ' MB', ' GB', ' TB'); for ($f = 0; $size = 1024 $f 4; $f++){$size /= 1024; }return roun

目前为止,发现可能是最快的计算方法
是不是还有更快的呢? PHP
<?php
date_default_timezone_set('UTC');

function format_bytes($size)
{ 
	$arr = array(' B', ' KB', ' MB', ' GB', ' TB'); 
	for ($f = 0; $size >= 1024 && $f < 4; $f++)
	{
		$size /= 1024; 
	}
	return round($size, 2).$arr[$f]; 
}
echo format_bytes('123456789');
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn