php convert bytes to mb

Solutions on MaxInterview for php convert bytes to mb by the best coders in the world

showing results for - "php convert bytes to mb"
Matías
03 Mar 2019
1function toByteSize($p_sFormatted) {
2    $aUnits = array('B'=>0, 'KB'=>1, 'MB'=>2, 'GB'=>3, 'TB'=>4, 'PB'=>5, 'EB'=>6, 'ZB'=>7, 'YB'=>8);
3    $sUnit = strtoupper(trim(substr($p_sFormatted, -2)));
4    if (intval($sUnit) !== 0) {
5        $sUnit = 'B';
6    }
7    if (!in_array($sUnit, array_keys($aUnits))) {
8        return false;
9    }
10    $iUnits = trim(substr($p_sFormatted, 0, strlen($p_sFormatted) - 2));
11    if (!intval($iUnits) == $iUnits) {
12        return false;
13    }
14    return $iUnits * pow(1024, $aUnits[$sUnit]);
15}
Caterina
03 Jan 2020
1<?php
2// Snippet from PHP Share: http://www.phpshare.org
3
4    function formatSizeUnits($bytes)
5    {
6        if ($bytes >= 1073741824)
7        {
8            $bytes = number_format($bytes / 1073741824, 2) . ' GB';
9        }
10        elseif ($bytes >= 1048576)
11        {
12            $bytes = number_format($bytes / 1048576, 2) . ' MB';
13        }
14        elseif ($bytes >= 1024)
15        {
16            $bytes = number_format($bytes / 1024, 2) . ' KB';
17        }
18        elseif ($bytes > 1)
19        {
20            $bytes = $bytes . ' bytes';
21        }
22        elseif ($bytes == 1)
23        {
24            $bytes = $bytes . ' byte';
25        }
26        else
27        {
28            $bytes = '0 bytes';
29        }
30
31        return $bytes;
32}
33?>
34
Christopher
06 Jun 2017
1<?php 
2  function tobytes($size, $type)
3  {
4    $types = array("B", "KB", "MB", "GB", "TB", "PB"); //You can add the rest if needed..
5    
6    if($key = array_search($type, $types))
7      return $size * pow(1024, $key);
8    else return "invalid type";
9  }
10  
11  echo tobytes(15, "MB"); //15728640
12  echo tobytes(2, "KB"); //2048
13  echo tobytes(3, "w/e"); //invalid type 
14?>
15
Kathleen
12 Jan 2017
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} 
queries leading to this page
php trans byte to megabytesphp bytes to kbphp convert byte to megabytesphp show bytes as mbfunction convert mb to bytes phpbyte convert phpphp convert bit to kilobytes or megabytesphp convert kb mb gb tb etc to bytessize to mb phpphp bytwes to kbbytes to mb phpphp bytes to gbphp gigabytes to bytesconvert gb to bytes phpconvert bit to megabyte php functionhow to convert mb to gb phpbytes to megabytes phpbyte to gb phpphp bytes to mb conversion bytes to megabites phpphp convert to megabytsconver bytes to gb with phphow to transfer mb into gb phpphp mb in gbphp convert mg to bytesparse kb to mb phpphp convert bytes to mbconvert kb to mb phplaravel bytes to mbphp format gb to bytesconvert bytes to mb in phpbytes to mb in phpmb to bytes phpbyte to mb phpbytes to mb converter php scriptconvert byte to mb phpphp format byteskb to mb phpconvert from byte to gb phpconvert bytes to kilobytes in phphow to convert from bytes to mb in phphow to convert from mb to bytes in phpphp format file sizebype to mb phpconvert kb to bytes phpkb to mb converter phpphp bytes to mbytesphp bytes to mbconvert bytes to megabytes in phpformat bytesphp convert mb to bytesphp format gb mb kb to bytesconvert bytes to gb in phpphp formula to convert from byte to mbphp byts in mbphp byte to mbconvert byte to megabyte phpconvert 20m into kb phpconvert bytes to mb phpbyte to mb to gb converter phpphp bytes to mbpsconvert byte to gb phpbytes to gb phpphp convert bytes to megabytesphp byte to gblaravel bytes to kbconvert 1gb to bytes phpset mb language in phpphp bytes to gigabytesconvert byte to mb in phpsize converter phpconvert bytes to mb gb in phpbytes to mb formula phpphp convert bytes to gbmb to bytes in phpphp convert bytes to kb mb gbphp function bytes to megabytesphp convert kb to mbphp bytes to petabytesphp convert bytes to mb