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

Random string generator...

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

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

Best way to get user ip address in php...

Here is a function to getting ip using filter of local and lan ip's. function get_ip() { $list = array( 'REMOTE_ADDR', 'CLIENT_IP', 'HTTP_CLIENT_IP', 'HTTP_PROXY_CONNECTION',...

Extract numbers from a unicode string...

Quick extract numbers from a unicode string......