T
T
teodor7teodor72020-01-15 14:46:29
Yii
teodor7teodor7, 2020-01-15 14:46:29

How to delete and save images kartik\file\FileInput in Yii2?

I use kartik\file\FileInput https://plugins.krajee.com/file-plugin-methods-demo

<?= $form->field($model, 'imageFile')->widget(FileInput::classname(), [
                'options' => ['accept' => 'image/*'],
        'pluginOptions' => [
            'initialPreview'=> [
            (new common\models\Pricelist)->logoLink ? (new common\models\Pricelist)->logoLink : NULL,
                 ],
            'showPreview' => true,
            'showCaption' => false,
            'showRemove' => false,
            'showUpload' => false,
            'showBrowse' => false,
            'browseOnZoneClick' => true,

            'initialPreviewAsData'=>true,
            'allowedFileExtensions'=>['jpg','jpeg','gif','png'],
        ]
                ]); ?>

5e1efad39ab47745978502.png
You just need to do a download without ajaxes and bells and whistles. It turns out when I upload a file and save everything works, when I refresh the page I deduce that the file has loaded. There was a question with removal. If the form is empty, I delete the file that is contained in memory. This is the problem, because the widget does not transmit the current state - whether there is a file or not in the case when it is already loaded.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
teodor7teodor7, 2020-01-16
@teodor7teodor7

Solved the problem with a hidden field.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question