Skip to content

Instantly share code, notes, and snippets.

@emiliojva
Created April 10, 2019 16:08
Show Gist options
  • Save emiliojva/d894833bf8dbafc5e0e3bb68c9f2c4ea to your computer and use it in GitHub Desktop.
Save emiliojva/d894833bf8dbafc5e0e3bb68c9f2c4ea to your computer and use it in GitHub Desktop.
<?php
function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824)
{
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
}
elseif ($bytes >= 1048576)
{
$bytes = number_format($bytes / 1048576, 2) . ' MB';
}
elseif ($bytes >= 1024)
{
$bytes = number_format($bytes / 1024, 2) . ' KB';
}
elseif ($bytes > 1)
{
$bytes = $bytes . ' bytes';
}
elseif ($bytes == 1)
{
$bytes = $bytes . ' byte';
}
else
{
$bytes = '0 bytes';
}
return $bytes;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment