Last active
December 25, 2015 04:39
-
-
Save Kcko/6918526 to your computer and use it in GitHub Desktop.
PHP: Readable filesize
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
<? | |
function HumanReadableFilesize($size) { | |
// Adapted from: http://www.php.net/manual/en/function.filesize.php | |
$mod = 1024; | |
$units = explode(' ','B KB MB GB TB PB'); | |
for ($i = 0; $size > $mod; $i++) { | |
$size /= $mod; | |
} | |
return round($size, 2) . ' ' . $units[$i]; | |
} | |
function fsize($file) { | |
$a = array("B", "KB", "MB", "GB", "TB", "PB"); | |
$pos = 0; | |
$size = filesize($file); | |
while ($size >= 1024) {$size /= 1024;$pos++;} | |
return round($size,2)." ".$a[$pos]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment