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>
2
  • yes you can store image files in MYSQL databases, just use the BLOB column type. Commented Apr 5, 2013 at 0:51
  • Possible duplicate: stackoverflow.com/questions/166221/… Commented Apr 5, 2013 at 0:53

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answer and your help. I solved problem with this script.
Is possible send form data WITH image in mysql with ajax?
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.