I
I
iceman21122014-09-30 13:33:24
Yii
iceman2112, 2014-09-30 13:33:24

How to change the number of possible files depending on their type?

How can I make it so that if the user can select only 1 pdf file, or several jpg.?
The form:

<?= $form->field($model, 'tmpFile')->textInput(['multyple' => true]);

Rules:
[['tmpFile'], 'file' 'extenstions' => 'jpf, pdf', 'mime-types' => 'image/jpef, application/pdf', 'maxFiles' => 5]

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
amstr1k, 2014-09-30
@amstr1k

Group files by type and then check

if(count($arr['jpg']) > 5 || count($arr['pdf']) > 1 )
  return;

A
Alexander Zelenin, 2014-09-30
@zelenin

You need to create a separate validator and validate in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question