0
votes

Now the problem with kartik widget is in the form view after you upload the first photo( before submiting the form) for the other next ones it just gets overwrite on the previous ones and the only preview in the field is for the last uploaded one.

 <?= $form->field($model, 'image')->widget(FileInput::classname(), [
                'name'=> 'ads_photos[]',
                'options'=>['accept'=>'image/*', 'multiple'=>true, ],
                'pluginOptions'=>[
                'allowedFileExtensions'=>['jpg','gif','png'],
                'overwriteInitial'=>false,
                ]
            ]); 
        ?>

as you can see I've set 'multiple'=>true, and 'overwriteInitial'=>false, as far as you can see in the guide it has said the same.
but what's the problem?

2
have you found the solution i am also facing the same problem - rajwa766
@Sajid sorry to say that but I changed the whole project. I couldn't find the solution. - Amir

2 Answers

0
votes

You need to read the guide more careful:

Note: When using the widget to upload multiple files you must name the HTML input in array format by appending [] to the input/attribute name. Check the examples for usage.

0
votes

Did you tried by setting default initial preview. suppose if your widget dont have any previous images then set the default image like we put default avatar for profile photo.

Try this by setting initial preview property

<?= $form->field($model, 'image')->widget(FileInput::classname(), [
                'name'=> 'ads_photos[]',
                'options'=>['accept'=>'image/*', 'multiple'=>true, ],
                'pluginOptions'=>[
                'allowedFileExtensions'=>['jpg','gif','png'],
                'initialPreview'=>[
            "http://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/FullMoon2010.jpg/631px-FullMoon2010.jpg",
        ],
        'overwriteInitial'=>false,
        'initialPreviewAsData'=>true,
                ]
            ]); 
        ?>

Hope it will help you