Skip to content

Instantly share code, notes, and snippets.

@ikawka
Created March 6, 2014 02:30
Show Gist options
  • Select an option

  • Save ikawka/9381103 to your computer and use it in GitHub Desktop.

Select an option

Save ikawka/9381103 to your computer and use it in GitHub Desktop.
Human readable filesize
<?php
function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment