Home >Backend Development >PHP Tutorial >Implementation code for php formatted file size

Implementation code for php formatted file size

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:59:49934browse
This article introduces a PHP code that implements formatted file size. The so-called formatted file size means that the file size in bytes is displayed in an easy-to-read manner, such as 120GB, 30MB, etc.

The code is as follows:

<?php
/**
* 格式化文件大小
* Edit bbs.it-home.org
*/
function format($size)
{
$sizetext = array(" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return round($size/pow(1024,($i=floor(log($size,1024)))),2).$sizetext[$i];
}
?>


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