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

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] != "+" ) { ...

URL Checker...

This function check if an url is valid or not. function is_valid_url($url) { return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); }...

Random string generator...

Random string generator. Optionally, you can give it a desired string length. function rnd_string($len = 24) { $str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $str...

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 ) ...