Answer the question
In order to leave comments, you need to log in
How to make multiple upload files in Yii2?
How to make multiple upload files in yii2? I found solutions to this problem, but there it was solved through the model, but I need it through the controller.
Here is my code
public function actionAdd_damage(){
$postDamage = new Damage_list();
if($postDamage->load(Yii::$app->request->post()) && $postDamage->validate()){
$imageDamage = UploadedFile::getInstance($postDamage, 'photo');
$postDamage->photo = 'uploads/'.md5($imageDamage->baseName).'.'.$imageDamage->extension;
if($postDamage->save()){
$imageDamage->saveAs($postDamage->photo);
Yii::$app->getSession()->setFlash('message', 'Post published successfull');
return $this->redirect(['site/table']);
}
else{
Yii::$app->getSession()->setFlash('message', 'Failed to post');
}
}
return $this->render('add_damage', ['postDamage' => $postDamage]);
}
<?=$form->field($postDamage, 'photo[]')->fileInput('multiple'=>true)?>
private $date;
private $description;
private $photo;
private $compence;
private $come;
public function rules()
{
return [
,
[['photo'], 'file', 'extensions' => 'png, jpg, pdf', 'maxFiles' => 10, 'skipOnEmpty'=>false]
];
}
Answer the question
In order to leave comments, you need to log in
Good afternoon.
The controller is called a controller because it should control, and not perform something ...))) This is a rough explanation, but ...
What exactly is not working for you, add to your question.
And replace the line
on the
$imageDamage = UploadedFile::getInstances($postDamage, 'photo');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question