blob: 80a7a6036dfa7d1f5e7af5d4664a1b0e4a32605a [file] [log] [blame]
Derek Allard0f109192008-06-19 18:09:13 +00001<?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 */
37if ( ! function_exists('byte_format'))
38{
39 function byte_format($num)
40 {
Derek Allard85f66ea2008-06-26 17:03:38 +000041 $CI =& get_instance();
42 $CI->lang->load('number');
Derek Jonese37fa052008-06-30 00:22:42 +000043
Derek Allard0f109192008-06-19 18:09:13 +000044 if ($num >= 1000000000000)
45 {
Derek Jonese37fa052008-06-30 00:22:42 +000046 $num = round($num / 1099511627776, 1);
47 $unit = $CI->lang->line('terabyte_abbr');
Derek Allard0f109192008-06-19 18:09:13 +000048 }
49 elseif ($num >= 1000000000)
50 {
Derek Jonese37fa052008-06-30 00:22:42 +000051 $num = round($num / 1073741824, 1);
52 $unit = $CI->lang->line('gigabyte_abbr');
Derek Allard0f109192008-06-19 18:09:13 +000053 }
54 elseif ($num >= 1000000)
55 {
Derek Jonese37fa052008-06-30 00:22:42 +000056 $num = round($num / 1048576, 1);
57 $unit = $CI->lang->line('megabyte_abbr');
Derek Allard0f109192008-06-19 18:09:13 +000058 }
59 elseif ($num >= 1000)
60 {
Derek Jonese37fa052008-06-30 00:22:42 +000061 $num = round($num / 1024, 1);
62 $unit = $CI->lang->line('kilobyte_abbr');
Derek Allard0f109192008-06-19 18:09:13 +000063 }
64 else
65 {
Derek Allard85f66ea2008-06-26 17:03:38 +000066 $unit = $CI->lang->line('bytes');
67 return number_format($num).' '.$unit;
Derek Allard0f109192008-06-19 18:09:13 +000068 }
69
70 return number_format($num, 1).' '.$unit;
71 }
72}
73
74/* End of file number_helper.php */
Derek Jonesa935c3f2008-06-19 17:42:55 +000075/* Location: ./system/helpers/number_helper.php */