Last active
January 25, 2019 09:34
-
-
Save grena/5977137 to your computer and use it in GitHub Desktop.
Snippet to convert bytes size to human readable size in PHP.
This file contains 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
<?php | |
function filesize_formatted($path) | |
{ | |
$size = filesize($path); | |
$units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); | |
$power = $size > 0 ? floor(log($size, 1024)) : 0; | |
return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment