public function __construct($min = null, $max = null, $inclusive = false, $config = []) { parent::__construct($config); if (!is_null($min) && !is_null($max) && $min > $max) { throw new ValidateException(sprintf('%s cannot be less than %s for validation', $min, $max)); } $this->params['minValue'] = \rock\helpers\FileHelper::sizeToBytes($min); $this->params['maxValue'] = \rock\helpers\FileHelper::sizeToBytes($max); $this->params['inclusive'] = $inclusive; }
/** * Returns the maximum size allowed for uploaded files. * This is determined based on three factors: * * - 'upload_max_filesize' in php.ini * - 'MAX_FILE_SIZE' hidden field * - `maxSize` * * @param int|null $maxSize * @return integer the size limit for uploaded files. */ public static function getSizeLimit($maxSize = null) { $limit = FileHelper::sizeToBytes(ini_get('upload_max_filesize')); if ($maxSize !== null) { $maxSize = FileHelper::sizeToBytes($maxSize); if ($limit > 0 && $maxSize < $limit) { $limit = $maxSize; } } if (isset($_POST['MAX_FILE_SIZE']) && $_POST['MAX_FILE_SIZE'] > 0 && $_POST['MAX_FILE_SIZE'] < $limit) { $limit = (int) $_POST['MAX_FILE_SIZE']; } return $limit; }
public function __construct($minValue, $inclusive = false, $config = []) { parent::__construct($config); $this->params['minValue'] = FileHelper::sizeToBytes($minValue); $this->params['inclusive'] = $inclusive; }
public function __construct($maxValue = null, $inclusive = false, $config = []) { parent::__construct($config); $this->params['maxValue'] = class_exists('rock\\file\\UploadedFile') ? UploadedFile::getSizeLimit($maxValue) : FileHelper::sizeToBytes(ini_get('upload_max_filesize')); $this->params['inclusive'] = $inclusive; }