1

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>
Daniel Jaušovec
  • 217
  • 5
  • 15
  • yes you can store image files in MYSQL databases, just use the BLOB column type. – Tony Apr 05 '13 at 00:51
  • Possible duplicate: http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery – Jon Apr 05 '13 at 00:53

2 Answers2

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:

egig
  • 4,370
  • 5
  • 29
  • 50
0

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>
Vicky
  • 982
  • 2
  • 11
  • 28