1

I have and array files like so:

 Array (4)
 File {name: "1.jpg", lastModifiedDate: Thu Jun 16 2016 16:12:00 GMT+0200 (CEST), size: 76669, type: "image/jpeg", slice: function}
 File {name: "2.jpg", lastModifiedDate: Thu Jun 16 2016 16:12:00 GMT+0200 (CEST), size: 85341, type: "image/jpeg", slice: function}
 File {name: "3.jpg", lastModifiedDate: Thu Jun 16 2016 16:12:00 GMT+0200 (CEST), size: 46841, type: "image/jpeg", slice: function}
 File {name: "4.jpg", lastModifiedDate: Thu Jun 16 2016 16:12:00 GMT+0200 (CEST), size: 89657, type: "image/jpeg", slice: function}

Can I not just append this array to a FormData Object and then send it to my php script to process?

for example:

data.append("files[]", files_to_upload);

Or do I have to loop through the files array and append each file separately?

1

1 Answer 1

1

Ok, found it out.

// append files to the form data
for(var i=0; i<files_to_upload.length; i++){
    data.append("files[]", files_to_upload[i]);
}

just had to loop through the files array and append them one by one. the can access them nicely as usual via $_FILES

cheers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.