yiidoc / yii2-redactor

Extension Redactor WYSIWYG for Yii2 framework
BSD 3-Clause "New" or "Revised" License
186 stars 87 forks source link

Multiple images upload #58

Open Lapinskas opened 8 years ago

Lapinskas commented 8 years ago

I've faced the problem of multiple images upload and resulted in quick workaround. Please take more detailed view on this problem and eventually fix the multiple images upload functionality.

Problem:

  1. Current licensed version of WYSIWYG Redactor by Imperavi is version dated October 2015 (really old and outdated, please consider getting a fresh one!).
  2. Redactor supports multipleImageUpload setting only starting from version 1.2 dated December 16th, 2015

Workaround: I've found the problematic place in the redactor.js file

                onDrop: function (e) {
                    e = e.originalEvent || e;
                    var files = e.dataTransfer.files;

                    this.upload.traverseFile(files[0], e);

As you can see, only the first image will be uploaded, as it is hardcoded files[0] in the JavaScript. There are more similar hardcoded files[0] fragments.

So, small change to have a loop on all images helped me to solve the problem:

                onDrop: function (e) {
                    e = e.originalEvent || e;
                    var files = e.dataTransfer.files;

                    for (var index = 0; index < files.length; ++index) {
                        this.upload.traverseFile(files[index], e);
                    }

Now user can drop multiple files to the upload box and it works fine, except of progress bar that works incorrectly.

PS. No changes are needed on PHP side