CodeIgniter AJAX file upload, $_FILE is empty when upload CodeIgniter AJAX file upload, $_FILE is empty when upload codeigniter codeigniter

CodeIgniter AJAX file upload, $_FILE is empty when upload


The problem here is that I'm sending the array of files instead of the single files on the AJAX call, specifically in this part of the code:

for(var i = 0; i < files.length; i++) {    fd.append("file_" + i, files[i]);}

The solution was to append file by file to the formData instead of the array of files, something like this:

for(var i = 0; i < files[0].length; i++) {    fd.append("file_" + i, files[i]);}

This will append every single file of the files array instead of the array of files itself and it solves the problem.

In conclusion I was sending the array of files instead of the single files, the clue to this was the [object FileList] that the request was showing instead of the files information, which now makes a request like this:

Content-Disposition: form-data; name="file"; filename="exfile.pdf"Content-Type: application/pdf