validationfile-uploadyii2multi-upload

Yii2 - minSize and maxSize of the file validator apply to how many files?


From the Core Validators guide, the minSize and maxSize are described as

the minimum/maximum number of bytes required for the uploaded file.

But there's no explanation on how many files these properties apply to.

Is it per file or total size of all files?


Solution

  • In validator code it checks size in method validateValue(), so it's min/max size per file, not for all of them.

    From line 207:

    foreach ($files as $file) {
        $result = $this->validateValue($file);
    ...
    

    Error example:

    [
        "The file \"git-flow cheatsheet.png\" is too big. Its size cannot exceed 819.2 KiB.",
        "The file \"IMG_20170531_134929.jpg\" is too big. Its size cannot exceed 819.2 KiB.",
        "The file \"Lenovo sound recorder icon.jpg\" is too small. Its size cannot be smaller than 409.6 KiB.",
        "The file \"memorable-linux-milestone_502911b05dc45.jpg\" is too small. Its size cannot be smaller than 409.6 KiB."
    ]