I
I
Ivan Ivanov2021-01-24 12:55:06
Yii
Ivan Ivanov, 2021-01-24 12:55:06

Why is deleting one file in kartik-v-fileinput deleting all other files?

I am using yii2 kartik-v-fileinput to upload images. Everything works, however, when one file is deleted in the preview, all the others are deleted too (they remain in the preview, but an empty array reaches the server, and there are no files there)
Preview type:
600d436214ef9798724405.png
Field:

<?= $form->field($model, 'imgFiles[]')->widget(FileInput::class, [
                            'options' => ['accept' => 'image/*', 'multiple' => true, 'id' => 'img-456'],
                            'pluginOptions' => [
                                //'browseLabel' => '',
                                'showPreview' => true,
                                //'showCaption' => true,
                                //'dropZoneTitle' => '',
                                'showRemove' => true,
                                'showUpload' => false,
                                'showDelete' => true,
                                //'showUpload' => false,
                                //'showClose' => false,
                                //'previewFileType' => 'image',
                                'allowedFileExtensions' => ['jpg', 'png', 'jpeg'],
                                'maxFileCount' => 20,
                                'removeClass' => 'btn btn-danger img-btn',
                                'uploadUrl' => Url::to('some'),
                                'deleteUrl' => Url::to('site/delete-img'),
                            ]
                        ])->label(false) ?>

I catch pictures in the controller:
var_dump(UploadedFile::getInstances($form, 'imgFiles'));
                exit();

If you just download the files and do not delete anything, then everything is OK. If you select files and delete some, then an empty array reaches the server.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bashcode, 2021-01-27
@maksim_fix

Try to use the default configuration from the plugin examples.
Then turn on the properties one by one.
And it's not clear yet whether you send the drawings with the main form or separately. If separately, it needs to be handled a little differently.
If together uploadUrl seemed to be redundant.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question