floor numbers to mb gb kb php

Solutions on MaxInterview for floor numbers to mb gb kb php by the best coders in the world

showing results for - "floor numbers to mb gb kb php"
Justice
22 May 2016
1A cleaner approach:
2
3function Size($path)
4{
5    $bytes = sprintf('%u', filesize($path));
6
7    if ($bytes > 0)
8    {
9        $unit = intval(log($bytes, 1024));
10        $units = array('B', 'KB', 'MB', 'GB');
11
12        if (array_key_exists($unit, $units) === true)
13        {
14            return sprintf('%d %s', $bytes / pow(1024, $unit), $units[$unit]);
15        }
16    }
17
18    return $bytes;
19}