Skip to content
Advertisement

How do I send files(images) in an array in PHP via ajax?

JavaScript

Mistake https://i.stack.imgur.com/mtsAP.png

However, if you enter just:

JavaScript

It shows everything correctly https://i.stack.imgur.com/kNptA.png

PHP

JavaScript

Advertisement

Answer

From the console output in the second image it appears that fileList is an array of File objects. As such you should append them to a FormData object and set that as the data of your $.ajax() call. Try this:

JavaScript

From there you will need to use the $_FILES collection in PHP to access the files sent in the request, not $_POST.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement