Created
November 26, 2014 10:24
-
-
Save yanknudtskov/e879d594ba787e8325ef to your computer and use it in GitHub Desktop.
Get a filesize string
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 get_filesize_string($path) | |
{ | |
$bytes = sprintf('%u', filesize($path)); | |
if ($bytes > 0) | |
{ | |
$unit = intval(log($bytes, 1024)); | |
$units = array('B', 'KB', 'MB', 'GB'); | |
if (array_key_exists($unit, $units) === true) | |
{ | |
return sprintf('%d %s', $bytes / pow(1024, $unit), $units[$unit]); | |
} | |
} | |
return $bytes; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment