使用PHP、jQuery和AJAX将图像上传到数据库,而不是目标文件夹


image uploading to the database but not to the destination folder using PHP, jQuery and AJAX

我正在尝试使用PHP, AJAX和jQuery上传图像。图像上传完美没有ajax即只使用submit_post.php,但当我使用ajax它不成功,并提出了一个"错误"警报。我肯定在AJAX提交脚本中遗漏了一些东西。

脚本

submit.js

function submitForm(){
               $.ajax({

                      type : 'POST',
                      url  : 'submit_post.php',
                      data : $('#submit_post').serialize(),
                      dataType : 'json',
    mimeType: "multipart/form-data",
                      success : function(data){

                              console.log(data);

                              $('#btn-signup').html('<img src="ajax-loader.gif" /> &nbsp; signing up...').attr('disabled', 'disabled');
                               setTimeout(function(){
                                   if ( data.status==='success' ) {
                                       $('#errorDiv').slideDown(200, function(){
                                            $('#errorDiv').html('<div class="alert alert-info">'+data.message+'</div>');
                                            $('#errorDiv').delay(3000).slideUp(100);
                                            $("#submit_post")[0].reset();
                                            $('#btn-signup').html('<span class="glyphicon glyphicon-log-in"></span> &nbsp; Sign Me Up');
                                            $('#btn-signup').removeAttr('disabled');
                                       });
                                   } else {
                                        $('#errorDiv').slideDown(200, function(){
                                             $('#errorDiv').html('<div class="alert alert-danger">'+data.message+'</div>');
                                             $('#errorDiv').delay(3000).slideUp(100);
                                             $('#btn-signup').html('<span class="glyphicon glyphicon-log-in"></span> &nbsp; Sign Me Up');
                                             $('#btn-signup').removeAttr('disabled');
                                         });
                                   }
                               },3000);

                      },
                      error: function(){alert('Error!')}
               });
               return false;
           }

});

这与文件夹权限无关,因为没有AJAX,图像也可以上传。

使用下面编写的代码提交表单,然后尝试上传,请检查要上传图像的文件夹的权限

 $("#submit_post").on("submit", function(e) {
        e.preventDefault();
        $.ajax({
            url: "url.php",
            type: "POST",
            data: new FormData(this),
            dataType: "json",
            contentType: !1,
            cache: !1,
            processData: !1,
            success: function(e) {
            }
        })
    }),