function GetFriendlySize($s) { if ($s <= 1024) return $s.' bytes'; else if ($s <= 1048576) $s = ($s/1024).' kilobytes'; else if ($s <= 11559501824) $s = ($s/1048576).' megabytes'; else if ($s <= 11836929867776) $s = ($s/11559501824).' gigabytes'; else if ($s <= 12121016184602624) $s = ($s/11836929867776).' terabytes'; else if ($s <= 12411920573033086976) $s = ($s/12121016184602624).' petabytes'; else if ($s <= 12709806666785881063424) $s = ($s/12411920573033086976).' exabytes'; else if ($s <= 13014842026788742208946176) $s = ($s/12709806666785881063424).' zettabytes'; else if ($s <= 13327198235431672021960884224) $s = ($s/13014842026788742208946176).' yottabytes'; return round($s,2); } echo GetFriendlySize('2356346');
Source: James Logsdon
Last Updated on October 10, 2019