0

I'm creating a jQuery drag and drop upload. I've created everything perfectly so far and stored the files in an array.

Here's the final step:

$('.single-product form.cart').submit(function(e){
        e.preventDefault();
        console.table(files);

        $('.wcfu-validation').hide();

        var filetypes = ['image/png'];

        $.each(files, function(key, value, e){
            if($.inArray(value.type, filetypes)){
                $('.wcfu-validation').show();
            } else {
                $('input[type="file"]').prop('files', files);
            }
        });
    });

Here I'm checking to see if the uploaded file(s) is in the accepted file types array, if it is, then we can loop through each file in the files array and append to the HTML file input.

However, I'm getting this error: enter image description here

Here's what my array looks like as an example if I upload 2 PNG files: enter image description here

What am I doing wrong?

  • This question already has an answer here: https://stackoverflow.com/questions/6021526/programmatically-set-the-value-of-a-type-file-input-html-element – Periplo Oct 15 '19 at 20:25
  • Possible duplicate of [How to set a value to a file input in HTML?](https://stackoverflow.com/questions/1696877/how-to-set-a-value-to-a-file-input-in-html) – Twisty Oct 16 '19 at 00:59

0 Answers0