I am trying to store an image into an mysql database but in the ajax page $_FILE['textfield_Name']['temp_name']
is not recognizing it. Help me to solve this problem.
This is my file page code
<form class="form-horizontal signUPForm" method="post" action="most_wanted_ajax.php">
<label for="images">Upload Image</label>
<input type="file" name="images">
<br>
<button type="submit" id="add" value="Submit" >Add Most Wanted</button>
</form>
my jquery code is:
$("#add").click(function (e){
$.post($(".signUPForm").attr("action"),$(".signUPForm").serializeArray(),function(res){
if(res!=null){
alert("mosted wanted added");
}
else
{
alert("Somthing is fishy");
}
});
});
and here is my most_wanted_ajax.php code
<?php
if(getimagesize($_FILES['images']['tmp_name'])==FALSE)
{}
else
{
$image=addslashes($_FILES['images']['tmp_name']);
$image= file_get_contents($image);
$image= base64_encode($image);
$con=mysqli_connect("localhost","root","","ecopsweb");
$insertSQL="insert into most_wanted(images) values('".$image."')";
$rs= mysqli_query($con, $insertSQL);
$id= mysqli_insert_id($con);
header("location: missing_person_info.php");
}
?>
in the most_wanted_ajax.php page give two errors
Notice: Undefined index: images in C:\wamp\www\eCopsWeb\adminModule\most_wanted_ajax.php on line 3
Warning: getimagesize(): Filename cannot be empty in C:\wamp\www\eCopsWeb\adminModule\most_wanted_ajax.php on line 3
Add enctype="multipart/form-data"
> to your form tag.This value is required when you are using forms that have a file upload control
It would be
<form class="form-horizontal signUPForm" method="post" action="most_wanted_ajax.php" `enctype="multipart/form-data"`>