Created
December 1, 2019 05:38
-
-
Save alvnfaiz/1b5655229a9a15da81c33635ec40b7cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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