0

I'm trying to upload files from a form asynchronously, but I have a problem

I add the form files this way

function composeFormData(oldFormData,form){

    oldFormData.push({name:"doc_files",value:doc_filestore});
    oldFormData.push({name:"desc_files",value:filestore});

    $.ajax({
      url: "save.php",
      data: oldFormData,
      type: "POST", 
      dataType:"html",
      enctype: 'multipart/form-data',
      //processData: false
    }).done(function(response) {
      console.log(response);
    });

}

without processData: false ,the value of doc_files,and desc_files are a string instead of a file and with processData: false, $_POST is empty. But before send the request formdata['desc_files'] and formdata['doc_files'] are files arrays.

What am I doing wrong?

Jino Shaji
  • 1,097
  • 14
  • 27
afs_imi3
  • 1
  • 1
  • From the context of your code, `oldFormData` appears to be an array. If so, that's your problem. It needs to be a `FormData` object. I'm closing this as a duplicate as there are literally hundreds of questions asking about how to upload files from jQuery to PHP, and the logic is identical. – Rory McCrossan Sep 12 '17 at 07:52
  • oldFormData is formdata – afs_imi3 Sep 12 '17 at 07:53
  • In that case you will be getting an error as `push()` is not a method of a `FormData` object. Either way, the exact code you need is in the duplicate. – Rory McCrossan Sep 12 '17 at 07:54

0 Answers0