User upload binary data or image to store in MySQL BLOB data type column using PHP PDO
Displaying the uploading form.
BLOB: binary large object
User will enter the name of the Student ( t1 ) , Select one of the available ID (id ) and choose the file to upload by using file browser.
echo "<form action='uploadck.php' method=post
enctype='multipart/form-data' >
Name : <input type=text name=t1><br>
Select one ID :<select name=id>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
</select><br>
Upload this file: <input type=file name='file_up'>
<input type=submit value='Upload Image'></FORM>";
Processing the uploaded data with image.
Data is collected by using POST method. config.php is the database connection file. After upload, the image is available as $_FILES[file_up][tmp_name].
require 'config.php'; // database connection file.
require 'menu.php';
$id=$_POST['id'];
$student=$_POST['t1'];
$photo= fopen($_FILES[file_up][tmp_name], 'rb');
$query="insert into student_profile(id,student,profile_photo)
values(:id,:student,:profile_photo)";
$step=$dbo->prepare($query);
$step->bindParam(':id',$id,PDO::PARAM_INT, 3);
$step->bindParam(':student',$student,PDO::PARAM_STR, 10);
$step->bindParam(':profile_photo',$photo,PDO::PARAM_LOB);
if($step->execute()){
echo " Data with Photo is added ";
}
else{
echo " Not able to add data please contact Admin ";
print_r($step->errorInfo());
}