Skip to content

Instantly share code, notes, and snippets.

@andreruffert
Created November 17, 2010 17:03
Show Gist options
  • Save andreruffert/703653 to your computer and use it in GitHub Desktop.
Save andreruffert/703653 to your computer and use it in GitHub Desktop.
Returns a file-size in a more legible format
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