not able to save 2 files from 1 form in codeigniter

前端 未结 2 1271
死守一世寂寞
死守一世寂寞 2021-01-16 02:30

I have a form that requires a user to upload 2 files, file-upload & imgupload. I am trying to save the entire form through ajax.

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-16 02:53

    Try this one

    JS Code

    $("#save").click(function()
      {
        var formData = new FormData();
    
        $f1 = $('#file-upload');
        $f2 = $('#imgupload');
    
        formData.append('file-upload', $f1.get(0).files[0]);
        formData.append('imgupload', $f2.get(0).files[0]);
    
        jQuery.ajax(
          {
            type: "POST",
            url: "" + "comp/wfc",
            data: formData,
            processData: false,
            contentType: false,
            success: function(res) 
              {
                console.log(res);
                alert(res);
              }
          });
      });
    

    FYI, You can try below too if you are not aware of

    Instead of multiple file input try to the single file input with multiple = "multiple"

    
    

提交回复
热议问题