convert byte to megabyte php

Solutions on MaxInterview for convert byte to megabyte php by the best coders in the world

showing results for - "convert byte to megabyte php"
Hilda
31 Nov 2018
1function formatBytes($bytes, $precision = 2) { 
2    $units = array('B', 'KB', 'MB', 'GB', 'TB'); 
3
4    $bytes = max($bytes, 0); 
5    $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); 
6    $pow = min($pow, count($units) - 1); 
7
8    // Uncomment one of the following alternatives
9    // $bytes /= pow(1024, $pow);
10    // $bytes /= (1 << (10 * $pow)); 
11
12    return round($bytes, $precision) . ' ' . $units[$pow]; 
13}