Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php convert bytes to mb

<?php
// Snippet from PHP Share: http://www.phpshare.org

    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;
}
?>
Comment

php convert mb to bytes

function toByteSize($p_sFormatted) {
    $aUnits = array('B'=>0, 'KB'=>1, 'MB'=>2, 'GB'=>3, 'TB'=>4, 'PB'=>5, 'EB'=>6, 'ZB'=>7, 'YB'=>8);
    $sUnit = strtoupper(trim(substr($p_sFormatted, -2)));
    if (intval($sUnit) !== 0) {
        $sUnit = 'B';
    }
    if (!in_array($sUnit, array_keys($aUnits))) {
        return false;
    }
    $iUnits = trim(substr($p_sFormatted, 0, strlen($p_sFormatted) - 2));
    if (!intval($iUnits) == $iUnits) {
        return false;
    }
    return $iUnits * pow(1024, $aUnits[$sUnit]);
}
Comment

PREVIOUS NEXT
Code Example
Php :: how to populate dropdown list with array values in php 
Php :: check if valid url php 
Php :: carbon start of day 
Php :: php document root 
Php :: php generate random alphanumeric string 
Php :: laravel migration data types 
Php :: laravel uppercase first letter 
Php :: php memory_limit unlimited 
Php :: get image extension in php 
Php :: clear log file laravel command 
Php :: laravel meilisearch flush 
Php :: laravel 7 error npm run dev 
Php :: php 3 digit decimal 
Php :: php get ip to location 
Php :: php remove last element array 
Php :: Failed to connect to github.com port 443: Connection timed out 
Php :: laravel validate telephone number 
Php :: make a forign key in migrations using laravel 8 
Php :: tmp cakephp name 
Php :: complete url php 
Php :: hide wordpress errors 
Php :: group by codeigniter 3 
Php :: carbon add days from specific date 
Php :: php console output 
Php :: laravel withtrashed 
Php :: php get ip address of visitor 
Php :: php close window after script runs 
Php :: using js variable in php 
Php :: Your Composer dependencies require a PHP version "= 7.3.0" 
Php :: Remove “/public” from Laravel route 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =