Image upload, ajax, php, mysql

爱⌒轻易说出口 提交于 2020-01-23 17:59:11

问题


I have one question. Is possible upload image from file input to MySQL with Ajax POST and PHP?

Like this:

<script type="text/javascript">
$(document).ready(function(){
    $("button").click(function(){
    $("#form_id").submit(function(){
            $.ajax({
            type:"POST",
                data:image_data,
                url:"/path_to_php/ImageSave.php",
                success: function(msg){
                        alert("ok");
                    }
            });
            return false;
        });
    });
});
</script>
<form name="form_name" id="form_id" action="#" method="POST">
    <input type="file" name="image" id="image" />
    <button>Save</button>
</form>

回答1:


upload file and store it on database can be done by several ways. this is one tutorial for doing this.. But the problem is if you want to do that using Ajax, it is definitely possible, check this out but almost common browser doesnt support it, the solution is:

  • using iframe: check this tutorial
  • using jquery plugin check this article



回答2:


Try this.

<script type="text/javascript">
    $(document).ready(function(){
    $("#button").click(function(){
     var form_data = $('#reg_form').serialize();
    $.ajax({
        type:"POST",
        url:"/path_to_php/ImageSave.php",
        data:form_data,
        success: function(data)
        {
            $("#info").html(data);
        }

    });
    }); 

    });
    </script>


来源:https://stackoverflow.com/questions/15824177/image-upload-ajax-php-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!