Skip to content

Instantly share code, notes, and snippets.

@vhdm
Created September 6, 2015 21:25
Show Gist options
  • Save vhdm/0b550a176d355bd9bece to your computer and use it in GitHub Desktop.
Save vhdm/0b550a176d355bd9bece to your computer and use it in GitHub Desktop.
Human readable file size
<?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