Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hexl opened this issue May 11, 2015 · 2 comments
Open

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

hexl opened this issue May 11, 2015 · 2 comments

Comments

@hexl
Copy link

hexl commented May 11, 2015

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.

@hexl hexl changed the title Bug file remove bug, see detail... Bug file remove bug, see detail below... May 11, 2015
@CTOlet
Copy link
Owner

CTOlet commented Jan 13, 2016

Still cannot realize when and how does it happen.

@m1roff
Copy link

m1roff commented Jun 1, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants