[[+content_image]]
V
V
Vladislav2022-01-31 15:42:42
PHP
Vladislav, 2022-01-31 15:42:42

Yi2 Rules extensions not working correctly?

$model = DynamicModel::validateData(compact('files', 'file', 'userId'),
        [
            [['userId'], 'integer', 'min' => 1],
            [['file'], 'file', 'extensions' => 'xls, xlsx', 'maxSize' => 50 * 1024 * 1024],
            [['files'], 'each', 'rule' => ['file', 'extensions' => 'xls, xlsx', 'maxSize' => 50 * 1024 * 1024]],
        ]);


There is such a code.
When loading a file with the xlsx extension, everything goes fine, I try to load xls - I get the following error:
Разрешена загрузка файлов только со следующими расширениями: xls, xlsx.


What could be the problem? Maybe I wrote the rules wrong?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
V
Vladislav, 2022-01-31
@cr1gger

As IvanMogilev wrote in the code, the problem was in checkExtensionByMimeType.
That file with the xls extension that I loaded was going through php as an upload. And apparently the library that is used does not prescribe Mime Type, and in Yii this check is enabled by default: https://www.yiiframework.com/doc/api/2.0/yii-valid...

S
Sergey, 2022-01-31
@werwolflg

Extensions must be specified as an array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question