Skip to content

Instantly share code, notes, and snippets.

@jacmaes
Forked from Da-Fecto/human_filesize.php
Created January 28, 2016 10:12
Show Gist options
  • Save jacmaes/96e4271260dfee905d65 to your computer and use it in GitHub Desktop.
Save jacmaes/96e4271260dfee905d65 to your computer and use it in GitHub Desktop.
// author: http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment