blob: f158b1cdc65eb2bf493301bbcb9e06c6fadce883 [file] [log] [blame]
Derek Jonesa935c3f2008-06-19 17:42:55 +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 {
41 $num = (int) $num;
42
43 if ($num >= 1000000000)
44 {
45 $num = round($num/107374182)/10;
46 $unit = 'GB';
47 }
48 elseif ($num >= 1000000)
49 {
50 $num = round($num/104857)/10;
51 $unit = 'MB';
52 }
53 elseif ($num >= 1000)
54 {
55 $num = round($num/102)/10;
56 $unit = 'KB';
57 }
58 else
59 {
60 $unit = 'Bytes';
61 }
62
63 return number_format($num, 1).' '.$unit;
64 }
65}
66
67/* End of file number_helper.php */
68/* Location: ./system/helpers/number_helper.php */