Skip to content

Instantly share code, notes, and snippets.

@kazimolmez
Last active July 7, 2019 21:53
Show Gist options
  • Save kazimolmez/69c4a1c73b0af955d22e3190d315e271 to your computer and use it in GitHub Desktop.
Save kazimolmez/69c4a1c73b0af955d22e3190d315e271 to your computer and use it in GitHub Desktop.
Php file size format
function formatBytes($bytes, $precision = 2) {
$units = array("b", "kb", "mb", "gb", "tb");
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . " " . $units[$pow];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment