File size calculator

File size calculator function return file size format into kb, mb or gb.

function file_size($size, $out = 'kb', $precision = 2)
{
    switch ($out) {
        case 'kb':
            return round($size / 1024, $precision);
            break;
        case 'mb':
            return round($size / (1024 * 1024), $precision);
            break;
        case 'gb':
            return round($size / (1024 * 1024 * 1024), $precision);
            break;
    }
    return false;
}

Tags

No tag here.

Recommended pages

Better parse_str in php...

parse_str() is fine for simple stuff but it's not the same as PHP's built way of creating the $_GET magic variable. Why?!?......

Validate phone number...

Chek if a phone numbers is valid, according to its syntax (should be: "+390523599314"). True if it's valid, False otherwise function is_valid_phone( $phone ) { if ( $phone[0] != "+" ) { ...

Resize image function...

Resize image function for jpg format. $mood between max and min. if you choose max, this mean max size of image is $ta otherwise min size of image is $ta. function makeTheThumb( $ppath, $ta, $mood ) ...

UTF8 string length counter...

The best way to determine the character count of a UTF8 string. function strlen_utf8( $str ) { return mb_strlen( $str, 'UTF-8' ); }   //or... function strlen_utf8( $str ) { $c = 0;...