Last Updated on Thursday, 03 January 2013
Just a quick note on how to format a given filesize and to reduce the display output to a small string, eg:
- 196 bytes : displays as => "196 bytes"
- 12945 bytes : displays as => "12 Kb"
- 1478515 bytes : displays as => "1 Mb"
- 8798745455 bytes : displays as => "8 Gb"
How?
Source: PHP Share: http://www.phpshare.org
- function formatSizeUnits($bytes)
- {
- if ($bytes >= 1073741824)
- {
- $bytes = number_format($bytes / 1073741824, 2) . ' GB';
- }
- elseif ($bytes >= 1048576)
- {
- $bytes = number_format($bytes / 1048576, 2) . ' MB';
- }
- elseif ($bytes >= 1024)
- {
- $bytes = number_format($bytes / 1024, 2) . ' KB';
- }
- elseif ($bytes > 1)
- {
- $bytes = $bytes . ' bytes';
- }
- else
- {
- $bytes = '0 bytes';
- }
- return $bytes;
- }
Inline without a function
Source: Joes Brain: http://www.joellipman.com
- if ($this_file_size >= 1073741824)
- $this_file_size = number_format($this_file_size / 1073741824, 1) . ' GB';
- elseif ($this_file_size >= 1048576)
- $this_file_size = number_format($this_file_size / 1048576, 1) . ' MB';
- elseif ($this_file_size >= 1024)
- $this_file_size = number_format($this_file_size / 1024, 1) . ' KB';
- elseif ($this_file_size > 1)
- $this_file_size = $this_file_size . ' bytes';
- elseif ($this_file_size == 1)
- $this_file_size = $this_file_size . ' byte';
- else
- $this_file_size = '0 bytes';
Latest Posts
-
Joes Revolver Map (JRM)
-
Fri 17-May-13
Hmmm... Sounds like a problem with the identifier. Was it working before and has there been a change ...
-
Fri 17-May-13
Hello Joel: Yes, I do have it published on all pages of the site. I just went back to Revolver maps to ...
-
Fri 17-May-13
Hi Bill, From the developers of RevolverMaps, "the module would need to be published on every page ...
-
Fri 17-May-13
Hi Bill, I'll investigate further as you're not the first to say this happens. In the meantime, simply ...
-
Fri 17-May-13
Its a great extension. But when I set it up I only show my presence on the 3D map and no other visitors ...
-
Fri 17-May-13

