Yii2 - 文件验证器的minSize和maxSize适用于多少个文件?

时间:2017-06-21 08:24:27

标签: validation file-upload yii2 multi-upload

Core Validators指南中,req.open(“GET”, Xrm.Page.context.getClientUrl() + “/api/data/v8.0/privileges?fetchXml=” minSize被描述为

  

上传文件所需的最小/最大字节数。

但是没有解释这些属性适用的文件数量。

是每个文件还是所有文件的总大小?

1 个答案:

答案 0 :(得分:3)

在验证器代码中,它检查方法validateValue()中的大小,因此它是每个文件的最小/最大大小,而不是所有文件。

来自line 207

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

错误示例:

[
    "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."
]