Home  >  Article  >  Backend Development  >  PHP gets file size and converts gb, mb, kb code

PHP gets file size and converts gb, mb, kb code

高洛峰
高洛峰Original
2016-11-29 16:17:211090browse

This is a very smart code that uses php program to get the size of the file and displays the gb, mb, kb code according to the file size. The code is as follows:

function sizecount($filesize) {

if( $filesize >= 1073741824) {

$filesize = round($filesize / 1073741824 * 100) / 100 . ' gb';

} elseif($filesize >= 1048576) {

$filesize = round($ filesize / 1048576 * 100) / 100 . ' mb';

} elseif($filesize >= 1024) {

$filesize = round($filesize / 1024 * 100) / 100 . ' kb';

} else {//Open source code phpfensi.com

$filesize = $filesize . ' bytes';

}

return $filesize;

}

//Application method

$fenpath='./phpsi .com/logo.gif';

echo sizecount(filesize($path));


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