Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_View_Helper_FileSize Class Reference

Format a passed filesize in a friendlier manner. More...

List of all members.

Public Member Functions

 fileSize ($size, $precision=2)
 Takes the passed filesize and converts it to a friendlier format, such as: 12k 100M.

Static Protected Attributes

static $_suffixes = array('', 'K', 'M', 'G', 'T', 'P')

Detailed Description

Format a passed filesize in a friendlier manner.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

P4Cms_View_Helper_FileSize::fileSize ( size,
precision = 2 
)

Takes the passed filesize and converts it to a friendlier format, such as: 12k 100M.

Parameters:
string | int$sizethe value to format
int$precisionprecision of the result; defaults to 2
Returns:
string the formatted string.
    {
        $result = $size;
        $index = 0;
        while ($result > 1024 && $index++ < count(static::$_suffixes)) {
            $result = $result / 1024;
        }

        // no fractions for less than 1K
        if ($index == 0) {
            return sprintf('%d B', $result);
        }

        return sprintf('%1.' . $precision . 'f %sB', $result, static::$_suffixes[$index]);
    }

Member Data Documentation

P4Cms_View_Helper_FileSize::$_suffixes = array('', 'K', 'M', 'G', 'T', 'P') [static, protected]

The documentation for this class was generated from the following file: