Skip to content

Instantly share code, notes, and snippets.

@alvnfaiz
Created December 1, 2019 05:38
Show Gist options
  • Save alvnfaiz/1b5655229a9a15da81c33635ec40b7cf to your computer and use it in GitHub Desktop.
Save alvnfaiz/1b5655229a9a15da81c33635ec40b7cf to your computer and use it in GitHub Desktop.
function format_filesize( $bytes, $decimals = 2 )
{
$units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
for ( $i = 0; ( $bytes / 1024) > 0.9; $i++, $bytes /= 1024 ) {} // @codingStandardsIgnoreLine
return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[ $i ] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment