Last active
February 8, 2022 07:23
-
-
Save yehchge/f862716932bce5c155fd747a71a724f9 to your computer and use it in GitHub Desktop.
display filesize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function display_filesize($filesize){ | |
if(is_numeric($filesize)){ | |
$decr = 1024; $step = 0; | |
$prefix = array('Byte','KB','MB','GB','TB','PB'); | |
while(($filesize / $decr) > 0.9){ | |
$filesize = $filesize / $decr; | |
$step++; | |
} | |
return round($filesize,2).' '.$prefix[$step]; | |
} else { | |
return 'NaN'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment