Uploader\Helpers\Format::bytes PHP Method

bytes() public static method

Format byte code to human understand
public static bytes ( integer $bytes, integer $precision = 2 ) : string
$bytes integer number of bytes
$precision integer after comma numbers
return string
    public static function bytes($bytes, $precision = 2)
    {
        $size = array('bytes', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb', 'zb', 'yb');
        $factor = floor((strlen($bytes) - 1) / 3);
        return sprintf("%.{$precision}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor];
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Check maximum file size
  *
  * @param \Phalcon\Http\Request\File $file
  * @param mixed $value
  * @return bool
  */
 public function checkMaxsize(\Phalcon\Http\Request\File $file, $value)
 {
     //conversion to the desired format
     if (is_array($value) === true) {
         $value = $value[key($value)];
     }
     // check
     if ($file->getSize() > (int) $value) {
         $this->errors[] = sprintf(Message::get('INVALID_MAX_SIZE'), $file->getName(), Format::bytes($value));
         return false;
     }
     return true;
 }