0

I want to upload a file to php. The request should also contain a csrf token in the header. I therefore tried this code:

jQuery.ajax({
     type: 'POST',
     url: '../php/upload_handler.php',
     headers: {
         "CSRF": csrfToken
     },
     cache: false,
     contentType: false,
     processData: false,
     data: oFormData,
     success: fUploadSuccess,
     error: fError
});

but the $_FILES array is empty on PHP side. When I use the following approach (omitting the csrf token), it works:

var request = new XMLHttpRequest();
request.open("POST", "../php/upload_handler.php");
request.send(oFormData);

Why? What am I doing wrong?

Thanks

Rory McCrossan
  • 319,460
  • 37
  • 290
  • 318
AntonSack
  • 999
  • 2
  • 21
  • 44

0 Answers0