Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function formatBytes($bytes, $precision = 2)
- {
- $base = log($bytes) / log(1024);
- $suffixes = array('b', 'kb', 'Mb', 'Gb', 'Tb');
- return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
- }
- function formatSizeUnits($bytes)
- {
- if ($bytes >= 1073741824)
- {
- $bytes = number_format($bytes / 1073741824, 2) . ' GB';
- }
- elseif ($bytes >= 1048576)
- {
- $bytes = number_format($bytes / 1048576, 2) . ' MB';
- }
- elseif ($bytes >= 1024)
- {
- $bytes = number_format($bytes / 1024, 2) . ' KB';
- }
- elseif ($bytes > 1)
- {
- $bytes = $bytes . ' bytes';
- }
- elseif ($bytes == 1)
- {
- $bytes = $bytes . ' byte';
- }
- else
- {
- $bytes = '0 bytes';
- }
- return $bytes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement