Answer the question
In order to leave comments, you need to log in
What is wrong (Uploading Multiple Files)?
view:
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
echo $form->field($model, 'fileImage')->fileInput(['multiple' => true, 'accept' => 'image/*']);
public $fileImage;
public function rules()
{
return [
[['description_ru', 'description_en'], 'string', 'max' => 255],
[['fileImage'], 'file', 'maxFiles' => 5, 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif'],
];
}
public function actionCreate()
{
$model = new Works();
if ($model->load(Yii::$app->request->post())) {
if($_FILES){
echo '<pre>';
print_r($_FILES);
die();
}
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Array
(
[Works] => Array
(
[name] => Array
(
[fileImage] => ubuntu_bubbles_linux_93773_1366x768.jpg
)
[type] => Array
(
[fileImage] => image/jpeg
)
[tmp_name] => Array
(
[fileImage] => /tmp/phpT7u4pN
)
[error] => Array
(
[fileImage] => 0
)
[size] => Array
(
[fileImage] => 171551
)
)
)
Answer the question
In order to leave comments, you need to log in
look at the source code of the form, maybe something went wrong,
'extensions' => 'png, jpg, jpeg, gif' - I can't say for sure, but maybe you need to specify them in upper case, the files that you uploaded do not have the .JPG format?
In php.ini there is a setting for the number of simultaneously loaded files. Although there is rarely less than 5 configured. Well, the size is also there, limited, see php_info ().
The name of the input should be with []
at the end, as far as I know. For example, files[]
. Then each file will be a separate element in this array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question