Answer the question
In order to leave comments, you need to log in
Why is there an error when uploading two pictures?
I tried to organize the loading of two pictures from two fields figuratively like this
// form
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
<?= $form->field($model, 'logo')->fileInput([ 'accept' => 'image/*']) ?>
<?= $form->field($model, 'footer')->fileInput([ 'accept' => 'image/*']) ?>
<button>Submit</button>
<?php ActiveForm::end() ?>
// controller
<?php
$model->logo = UploadedFile::getInstance($model, 'logo');
$model->footer = UploadedFile::getInstance($model, 'footer');
if ($model->logo && $model->validate()) {
$model->logo->saveAs(Yii::getAlias('@frontend/web/').'/foto/' . $model->logo->baseName . '.' . $model->logo->extension);}
if($model->footer && $model->validate()){
$model->footer->saveAs(Yii::getAlias('@frontend/web/').'/foto/' . $model->footer->baseName . '.' . $model->footer->extension);}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question