I am trying to upload image using ajax on client side and on server side i am using PHP. The Problem i am facing is, i am unable to save the image in Mysql database table as a blob using PHP. I am unable to define Receive function of image.
I need help on how to define receive function and save blob image in database column.
am i missing something in my PHP code below ??
Java Script:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function (e) {
$("#uploadForm").on('submit',(function(e) {
e.preventDefault();
$.ajax({
url: "upload.php",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data)
{
$("#targetLayer").html(data);
},
error: function()
{
}
});
}));
});
</script>
HTML:
<form id="uploadForm" action="" method="post">
<div id="uploadFormLayer">
<label>Upload Image File:</label><br/>
<input name="userImage" type="file" class="inputFile" />
<input type="submit" value="Submit" class="btnSubmit" />
</form>
PHP:
$db = mysqli_connect("xxxx","xxx","xxx","xxx");
$image = addslashes(is_uploaded_file($_FILES['userImage']['tmp_name']));
$query = "INSERT INTO images (id,image) VALUES('','$image')";
$qry = mysqli_query($db, $query);