[[+content_image]]
H
H
HellWalk2017-09-06 15:12:18
Yii
HellWalk, 2017-09-06 15:12:18

Is there a validation rule for the size of the uploaded file?

I uploaded pictures, but there is not enough check for size.
Is there already a validation rule for file size that could be added to the rules:

public function rules()
    {
        return [
            [['imageFile'], 'file', 'extensions' => 'jpg, png, gif'],
        ];
    }

I know that you can connect fancy modules for processing pictures and files, or that you can write a check by hand on the property of the UploadedFile object. But the question is exactly how to do it simply and with the built-in features of Yii2.
Answer:
public function rules()
    {
        return [
            [['imageFile'], 'file', 'extensions' => 'jpg, png, gif', 'maxSize' => 1000000],
        ];
    }

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Anton, 2017-09-06
@karminski

Are you kidding me? Is it difficult to open documentation?
www.yiiframework.com/doc-2.0/yii-validators-fileva...
The maxSize parameter!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question