Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Created September 9, 2012 21:30
Show Gist options
  • Select an option

  • Save stefanocudini/3687432 to your computer and use it in GitHub Desktop.

Select an option

Save stefanocudini/3687432 to your computer and use it in GitHub Desktop.
convert size bytes to human
<?
function bytes2human($size)
{
$mod = 1024;
$units = array('B','KB','MB','GB','TB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2).$units[$i];
}
?>
@psykzz

psykzz commented Sep 9, 2012

Copy link
Copy Markdown

Does that actually work?

Is $i not local to the for loop and thus scrapped by the time you return it?

@stefanocudini

Copy link
Copy Markdown
Author

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment