Created
December 21, 2011 17:34
-
-
Save okjake/1506897 to your computer and use it in GitHub Desktop.
Printing pretty filesizes in a Drupal theme
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
| /* | |
| * Takes a filesize integer and returns a decently formatted string | |
| * This function needs to go into template.php, don't forget to change the theme name below | |
| * Call it like this: | |
| * - print mytheme_format_filesize($node->field_downloads[0]['filesize'] | |
| */ | |
| function mytheme_format_filesize($filesize) { | |
| if ($filesize < 1024) { | |
| return $filesize . ' bytes'; | |
| } | |
| elseif ($filesize < 1048576) { | |
| return round($filesize / 1024) . ' kB'; | |
| } | |
| else { | |
| return round($filesize / 1048576) . ' MB'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment