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

前端 未结 4 1113
有刺的猬
有刺的猬 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:08

    jQuery("#changePicture").click(function(){

        var file_name=jQuery("#imageInput").val();
        var fileName = jQuery("#imageInput").val();
        var fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1); 
    
    
        var base_url = 'Oppa/view/photo.php';
    
        var file_data=jQuery("#imageInput").prop("files")[0];
    
    
    
        var form_data=new FormData();
        form_data.append("file",file_data);
        jQuery.ajax({
        type:"POST",
        url: base_url,
        datatype:'script',
        cache:false,
        contentType:false,
        processData:false,
        data:form_data,
        success:function(){
        //------------
        },
        error:function(){
        //----------
        }
    
    
            });
    
    
        jQuery("#imageInput").val('');
    
    
        })
    

    i hope this would help for you n don't forget to like my ans

提交回复
热议问题