Skip to content

Instantly share code, notes, and snippets.

@hardevine
Created March 9, 2020 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardevine/cfd76fb238deac6ff7995aa359f73fe2 to your computer and use it in GitHub Desktop.
Save hardevine/cfd76fb238deac6ff7995aa359f73fe2 to your computer and use it in GitHub Desktop.
<?php
// Snippet from PHP Share: http://www.phpshare.org
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