Validates an image file size. Default max size is 5 MB.

@param Model $model
@param array $data
@param int $size
@return bool
761649
public function filesize(Model $model, $data, $size = 5242880) {
        return $this->_validate($model, $data, 'size', array($size));
    }
138465
protected function validateFileSize (int $allowedSize=0) : bool
	{
		$allowedSize = (!empty($allowedSize) AND $allowedSize >= 1) ? $allowedSize : $this->allowedFIleSize;
		if ($this->fileSize < $allowedSize) return TRUE;
		$this->error = "File is too large try another one.";
		return FALSE;			
	}
443792
public static function maxFilesize($input, $max) {
        if (static::file($input)) {
            $size = $input['size'];

        } else if (file_exists($input)) {
            $size = filesize($input);

        } else {
            return false;
        }

        return ($size <= Number::bytesFrom($max));
    }
892973
public function beforeValidationOnCreate(Event $event, Model $model)
    {
        if($model instanceof ITimestampable) {
            $now = $this->getNow();
            if(!$model->getCreatedAt()) {
                $model->setCreatedAt($now);
            }
            if(!$model->getUpdatedAt()) {
                $model->setUpdatedAt($now);
            }
        }
    }
1314567
public function validate(BaseModel $model, $rules = null, $messages = [])
    {
        return $this->validateAndPrefixErrors(null, $model, $rules, $messages);
    }
1365700
public function upload($model, $folderName, $files, $fileAttrName = 'files', $width = null)
    {
        $updatedFiles = $model->$fileAttrName;

        foreach ($files as $file) {

            $log = (new FileLog)->create([
                'model_id' => $model->id,
                'model_name' => $folderName,
                'file_original_name' => $file->getClientOriginalName(),
            ]);

            $systemFileName = $this->createSystemFileName($log, $file);
            $filePath = $this->createFilePath($folderName, $systemFileName);
            $folderPath = $this->createFilePath($folderName);

            Storage::put(
                $filePath,
                file_get_contents($file->path())
            );

            $log->fill([
                'file_path' => $filePath,
                'file_system_name' => $systemFileName
            ])->save();

            if ($width)
                $this->imageResize($width, $file, $filePath);

            $updatedFiles[] = [
                'file_log_id' => $log->id,
                'path' => asset($log->file_path),
                'file_original_name' => $log->file_original_name
            ];
        }

        $model->$fileAttrName = $updatedFiles;
        return $model;
    }
949438
public function upload($model, $request)
    {
        $files = $this->getFile($request);

        if (array_search(null,$files) === false) {
            foreach($files as $file) {
                $this->setFileName($file);
                $this->setFileSize($file);
                $this->files[] = $this->moveFile($file, $model);
            }
            return $this->files;
        }
        return false;
    }
1073891
public static function getImageFromArray($data, $size, $dimensions = false)
    {
        if($dimensions === true)
        {
            $image = (object) [
                'url' => $data['sizes'][$size],
                'width' => $data['sizes'][$size . '-width'],
                'height' => $data['sizes'][$size . '-height']
            ];
        }
        else
        {
            $image = $data['sizes'][$size];
        }
        return $image;
    }
881954
protected function _validate($column, $model, $data, $onlyIfAvailable) {
        if ($onlyIfAvailable && !array_key_exists($column, $data)) {
            return;
        }
        $value = array_key_exists($column, $data) ? $data[$column] : null;
        $colType = $this->_getColumnType($column, $model);

        if ($colType == 'numeric') {
            $this->_validateNumber($value, $column);
            return;
        }

        $this->_validateString($value, $column);
    }
540267
public function maxHeight(Model $model, $data, $size) {
        return $this->_validate($model, $data, 'maxHeight', array($size));
    }
819867
public function appendBytes($size, $data)
    {
        if ($size == 0)
            return 0;

        $b = QRbitstream::newFromBytes($size, $data);

        if(is_null($b))
            return -1;

        $ret = $this->append($b);
        unset($b);

        return $ret;
    }
634671
protected function validateAttributeInternal($model, $attribute)
    {
        $value = $model->{$attribute};

        $result = ($this->type == FormatHelper::TYPE_LIST)
            ? $this->validateListValue($model, $value)
            : $this->validateValue($value);

        if (!empty($result)) {
            $this->addError($model, $attribute, $result[0], $result[1]);

            return;
        }

        Yii::info('Type validation success'
            . PHP_EOL . "Result value for '$attribute': {$this->filteredAttribute}", __METHOD__);
        $model->{$attribute} = $this->filteredAttribute;
    }
1364971
protected function validateDimensions( $attribute, $value, $parameters )
	{
		if ( !$this->isAValidFileInstance( $value ) || !$sizeDetails = getimagesize( $value->getRealPath() ) )
		{
			return false;
		}

		$this->requireParameterCount( 1, $parameters, 'dimensions' );

		list( $width, $height ) = $sizeDetails;

		$parameters = $this->parseNamedParameters( $parameters );

		if ( isset( $parameters['width'] ) && $parameters['width'] != $width || isset( $parameters['min_width'] ) && $parameters['min_width'] > $width || isset( $parameters['max_width'] ) && $parameters['max_width'] < $width || isset( $parameters['height'] ) && $parameters['height'] != $height || isset( $parameters['min_height'] ) && $parameters['min_height'] > $height || isset( $parameters['max_height'] ) && $parameters['max_height'] < $height )
		{
			return false;
		}

		if ( isset( $parameters['ratio'] ) )
		{
			list( $numerator, $denominator ) = array_pad( sscanf( $parameters['ratio'], '%d/%d' ), 2, 1 );

			return $numerator / $denominator == $width / $height;
		}

		return true;
	}
149168
protected function extra_validation($data, $files, array &$errors) {
        $newerrors = array();
        // Move the error from scaleconfiguration to the form element scale ID.
        if (isset($errors['scaleconfiguration']) && !isset($errors['scaleid'])) {
            $newerrors['scaleid'] = $errors['scaleconfiguration'];
            unset($errors['scaleconfiguration']);
        }
        return $newerrors;
    }
254744
def validate_instance_size(self, size):
        '''  '''
        try:
            int(size)
        except ValueError:
            return '*** Error: size must be a whole number between 5 and 1024.'
        if int(size) < 5 or int(size) > 1024:
            return '*** Error: size must be between 5-1024 GB.'
        return True
1341189
public function afterValidate(Model $model) {
        if (!empty($this->_tempFiles)) {
            foreach ($this->_tempFiles as $file) {
                $file->delete();
            }
            $this->_tempFiles = array();
        }

        return true;
    }
719712
protected function validateSize($size)
    {
        if (! is_int($size) && ! ctype_digit($size)) {
            throw new \InvalidArgumentException('Avatar size specified must be an integer');
        }

        if ($size < 0 || $size > 2048) {
            throw new \InvalidArgumentException('Avatar size must be within 0 pixels and 2048 pixels');
        }
    }