Skip to content

Instantly share code, notes, and snippets.

View rwakos's full-sized avatar

Richard Reveron rwakos

View GitHub Profile
@rwakos
rwakos / gist:18136f64bfba430dd8221161b4395457
Created October 6, 2017 00:15
PHP - Get Filesize in different units, depending on its size
function getMaxUnitFromBytes($bytes)
{
if ($bytes < 1024) {
return $bytes . ' bytes';
} elseif (($bytes / 1024) < 1024) {
return ceil($bytes / 1024) . ' Kb';
} elseif (($bytes / (1024 * 1024)) < 1024) {
return ceil($bytes / (1024 * 1024)) . ' Mb';
} elseif (($bytes / (1024 * 1024 * 1024)) < 1024) {
return ceil($bytes / (1024 * 1024 * 1024)) . ' Gb';