Created
September 6, 2015 21:25
-
-
Save vhdm/0b550a176d355bd9bece to your computer and use it in GitHub Desktop.
Human readable file size
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 human_size ($size) { | |
if ($size <= 1024) return $size.' Bytes'; | |
else if ($size <= (1024*1024)) return sprintf('%d KB',(int)($size/1024)); | |
else if ($size <= (1024*1024*1024)) return sprintf('%.2f MB',($size/(1024*1024))); | |
else return sprintf('%.2f Gb',($size/(1024*1024*1024))); | |
} | |
echo human_size(32768); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment