CTOlet / yii2-attachments

Yii2 extension for uploading and attaching the files to the models
66 stars 57 forks source link

Bug file remove bug, see detail below... #17

Open hexl opened 9 years ago

hexl commented 9 years ago

Here is the scenario. The form with 3 fields(reciver, message, attachments) and a submit button. Step1, fill the reciver and message field. Step2, add any file and upload it. Step3, remove the files uploaded in Step2. Step4, add another files not added in Step2. Step5, submit the form data. Here goes the bug, you will find out that the files you delete in Step2 will display in the submit data and the attachments record will insert into the database.

Why? Because the code FileBehavior method saveUploads() will get all the files list in the specified folder. But the files deleted in Step2 still in the folder.

And my own sugesstion is add an event to the remove method. When user remove the file listed in the widgets, removing it from the temp folder at the same time.

CTOlet commented 8 years ago

Still cannot realize when and how does it happen.

m1roff commented 8 years ago

Ive got same problem, and cant solve it(( after upload contorller returns only file name I overload method actionUpload in FileController to return json data

{"initialPreviewConfig":[{"url":"/attachments/file/delete-temp?filename=pattern1.jpg","key":""}],"append":true}

but its not fixed problem.

Checked another project with native use of kartik\file\FileInput, everything works with json data above.

Some screenshots Your module init:

<?= AttachmentsInput::widget([
                    'id'      => Html::getInputId($model, 'files'), // Optional
                    'model'   => $model,
                    'options' => [ // Options of the Kartik's FileInput widget
                        'multiple' => true, // If you want to allow multiple upload, default to false
                        'accept'   => 'image/*',
                    ],
                    'pluginOptions' => [ // Plugin options of the Kartik's FileInput widget
                        // 'maxFileCount'          => 0,
                        'initialPreviewAsData' => true,
                        'overwriteInitial'      => true,
                        'showClose'             => false,
                        'showCaption'           => false,
                        'showUpload'            => true,
                        'uploadAsync'           => true,
                        'browseLabel'           => '',
                        'removeLabel'           => '',
                        'browseIcon'            => '<i class="glyphicon glyphicon-folder-open"></i>',
                        'removeIcon'            => '<i class="glyphicon glyphicon-remove"></i>',
                        'removeTitle'           => 'Cancel or reset changes',
                        // 'elErrorContainer'      => '#appeal-images-errors',
                        // 'msgErrorClass'         => 'alert alert-block alert-danger',
                        'defaultPreviewContent' => '<img src="/upload_image.png" alt="Фото проблемы" style="width: 160px">',
                        'layoutTemplates'       => "{main2: '{preview} ' +  btnCust + ' {remove} {browse}'}",
                        'allowedFileExtensions' => ["jpg", "png", "gif", "jpeg", 'svg'],
                    ]
                ]) ?>

2016-06-02_02-28-21

2016-06-02_02-29-19

And working project

<?=$form->field($model::photosModel(), 'uploadPhotos', ['template'=>"{label}\n{hint}\n{error}\n{input}\n"])
                ->hint($_photosHint, ['class'=>'alert alert-warning'])
                ->label(false)
                ->widget(FileInput::className(), [
            'name' => 'uploadPhotos[]',
            'options' => [
                'multiple' => true,
                'accept'   => 'image/jpg, image/png',
            ],
            'pluginOptions' => [
                'initialPreview'       => $model->photosInitialPreview(),
                'uploadUrl'            => \yii\helpers\Url::to(['/items/upload']),
                'uploadAsync'          => true,
                'overwriteInitial'     => false,
                'initialPreviewConfig' => $model->photosInitialPreviewConfig(),
                'uploadExtraData'      => ['id_items'=>$model->primaryKey],
                'maxImageWidth'        => 1600,
                'maxImageHeight'       => 1600,
            ],
            'pluginEvents' => [
                'filepredelete' => "function(){ return !confirm('Точно хотите удалить?')}"
            ],
        ]);?>

2016-06-02_02-29-57 2016-06-02_02-30-43