innostudio / fileuploader

Beautiful and powerful HTML file uploading tool. A jQuery, PHP and Node.js plugin that transforms the standard input into a revolutionary and fancy field on your page.
141 stars 25 forks source link

Problem with file upload on server (multiple instances) #44

Closed rabat1313 closed 5 years ago

rabat1313 commented 5 years ago

I have a problem with files upload to server when double use on same page. I use theme: "thumbnails", addMore: true and upload start: true. First uploader load images but doesn't upload to server's directory, second one is OK - everything works. I check consol's logs for onSuccess' results:

[...] onSuccess: function(result, item) { console.log(result); var data = {}; [...]

and I get in console:

{"hasWarnings":false,"isSuccess":false,"warnings":[],"files":[]}

Second file uploader is fine but I have a problem with first one... Any idea?

My instances:

$('#file_1').fileuploader({ extensions: ['jpg', 'jpeg', 'png'] }); $('#file_2').fileuploader({ extensions: null });

rabat1313 commented 5 years ago

OK, I see where the problem is... There is a problem with using API twice on same page. Any idea how fix it? Maybe any way to make dynamic API name?

innostudio commented 5 years ago

@rabat1313 are you using the following logic?

  1. Inputs

    <input type="file" name="files_1" id="file_1">
    <input type="file" name="files_2" id="file_2">
  2. .fileuploader()

    
    var $file1 = $('#file_1').fileuploader({
    enableApi: true
    });

var $file2 = $('#file_2').fileuploader({ enableApi: true });


3. API
~~~js
var api1 = $.fileuploader.getInstance($file1);

var api2 = $.fileuploader.getInstance($file2);
innostudio commented 5 years ago

@rabat1313 in PHP you also have 2 instances for 2 different uploaders, right?

$FileUplaoder1 = new FileUploader('files_1', array(...))
$FileUplaoder2 = new FileUploader('files_2', array(...))
rabat1313 commented 5 years ago

No, I use same PHP files (your fileuplader class and upload/delete files) for both instances.

innostudio commented 5 years ago

An instance of new FileUploader is used for one <input type="file">. So you need 2 instances for 2 different names.

rabat1313 commented 5 years ago

Everything works! Thank you!