Derek Allard | 0f10919 | 2008-06-19 18:09:13 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
| 8 | * @author ExpressionEngine Dev Team
|
| 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
| 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
| 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * CodeIgniter Number Helpers
|
| 20 | *
|
| 21 | * @package CodeIgniter
|
| 22 | * @subpackage Helpers
|
| 23 | * @category Helpers
|
| 24 | * @author ExpressionEngine Dev Team
|
| 25 | * @link http://codeigniter.com/user_guide/helpers/number_helper.html
|
| 26 | */
|
| 27 |
|
| 28 | // ------------------------------------------------------------------------
|
| 29 |
|
| 30 | /**
|
| 31 | * Formats a numbers as bytes, based on size, and adds the appropriate suffix
|
| 32 | *
|
| 33 | * @access public
|
| 34 | * @param mixed // will be cast as int
|
| 35 | * @return string
|
| 36 | */
|
| 37 | if ( ! function_exists('byte_format'))
|
| 38 | {
|
| 39 | function byte_format($num)
|
| 40 | {
|
| 41 |
|
| 42 | if ($num >= 1000000000000)
|
| 43 | {
|
| 44 | $num = round($num/1099511627776)/10;
|
| 45 | $unit = 'TB';
|
| 46 | }
|
| 47 | elseif ($num >= 1000000000)
|
| 48 | {
|
| 49 | $num = round($num/107374182)/10;
|
| 50 | $unit = 'GB';
|
| 51 | }
|
| 52 | elseif ($num >= 1000000)
|
| 53 | {
|
| 54 | $num = round($num/104857)/10;
|
| 55 | $unit = 'MB';
|
| 56 | }
|
| 57 | elseif ($num >= 1000)
|
| 58 | {
|
| 59 | $num = round($num/102)/10;
|
| 60 | $unit = 'KB';
|
| 61 | }
|
| 62 | else
|
| 63 | {
|
| 64 | $unit = 'Bytes';
|
| 65 | }
|
| 66 |
|
| 67 | return number_format($num, 1).' '.$unit;
|
| 68 | }
|
| 69 | }
|
| 70 |
|
| 71 | /* End of file number_helper.php */
|
Derek Jones | a935c3f | 2008-06-19 17:42:55 +0000 | [diff] [blame] | 72 | /* Location: ./system/helpers/number_helper.php */ |