Created
April 9, 2013 14:53
-
-
Save jrotering/5346347 to your computer and use it in GitHub Desktop.
Displays the file size of a file in the local filesystem (relative to MODX_BASE_PATH) in bytes, kilobytes, or megabytes depending on its size.
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
<?php | |
$path = MODX_BASE_PATH . $file; | |
$fs = filesize($path); | |
if ($fs < 1024) { | |
return "${fs}B"; | |
} | |
elseif ($fs < (1024*1024)) { | |
return round($fs / 1024, 0) .'KB'; | |
} | |
elseif ($fs < 1073741824) { | |
return round($fs / 1048576, 1) . 'MB'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just quick-and-dirty; assumes path is relative to MODX_BASE_PATH, and the unit descriptors are hard-coded. Adjust as necessary.