How to send input file data value using ajax to a php page

前端 未结 4 1081
有刺的猬
有刺的猬 2020-12-07 04:55

What I want to do is whenever a user selects a picture and click the button it will move the image to a specific folder and save the link to the database user_image column.<

4条回答
  •  有刺的猬
    2020-12-07 05:10

    try this,

    var data= false;
    if (window.FormData) {
         data= new FormData();
    }
        var email = $('#email').val();
    
    if (formdata) {
        data.append("image", $('input[type=file]')[0].files[0]);
        data.append("email","+email+");
        data.append("fileName",$('input[type=file]')[0].files[0].name);
     }
    
     if (data) {
              jQuery.ajax({
                        url: "php/upload.php",
                        type: "POST",
                        data: data,//Now you attached form datas with filename also,
                        processData: false,
                        contentType: false,
                        success: function (data) {
                           alert("Response  Data : "+data);
                        }
                    });
                }
    

提交回复
热议问题