Open srbhklkrn opened 8 years ago
I am having same issue. I am having multiple dynamic form in same view page and the multiple image upload is not working. I tried using simple fileInput field and also using Kartik's FileInput widget. Still not working. I always get empty image names after post.
Here is view code:
When i print posted values , I get blank image names:
[RecipeStep] => Array
(
[0] => Array
(
[id] => 2
[detail] => test22ingggg
[image] =>
)
[1] => Array
(
[id] => 3
[detail] => Test3
[image] =>
)
[2] => Array
(
[id] => 4
[detail] => Test2
[image] =>
)
)
This [image] => is always empty after post. I tried everything, but this is not working with image upload.
Please suggest how to sort this.
We get blank image names in $_POST array but when I print $_FILES I can see the image name array.
Have you solved this issue? even im facing the same problem. what to do?
Directly use $_FILES array, no other way to sort this. This is code sample of how I fetched uploaded images.
$cnt = 0; foreach ($models1 as $models1) {
//echo "<pre>";
//print_r($models1);
$models1->recipe_id = $recipeId;
/**** Save step recipe image *****/
$stepImg = $_FILES['RecipeStep']['name'][$cnt]['image'];
$tmpImg = $_FILES['RecipeStep']['tmp_name'][$cnt]['image'];
if ($stepImg != '') {
if (move_uploaded_file($tmpImg,"recipes/".$stepImg)) {
$models1->image = $stepImg;
} else {
Yii::$app->getSession()->setFlash('error', 'Error saving recipe images, Please enter valid images');
}
} //if img
if (! ($flag3 = $models1->save(false))) {
//echo "error for food product1cccc"; die;
$transaction->rollBack();
break;
}
$cnt++;
} //foreach
Hope this helps.
Im using Yii2 advanced. can i use this in that?
Yes, I am also using yii2 advanced and this worked for me.
Trying to upload multiple images through two dynamic forms containing each image file in section of the form, but unable to upload it.