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

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

高洛峰
Release: 2016-11-29 16:17:21
Original
1126 people have browsed it

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));


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template