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];
}
/** * 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; }