This is echo output of image I am storing an image as blob in a database as shown in the code below
<?php
// extract form values
if(isset($_POST['submit']))
{
$empnum = $_POST['emp_num'];
$lastname = $_POST['emp_lname'];
$firstname = $_POST['emp_fname'];
$initial = $_POST['emp_initial'];
$job = $_POST['job'];
$username = $_POST['emp_usr'];
$password = $_POST['emp_pass'];
$emp_bdate = $_POST['emp_bdate'];
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false){
$image = $_FILES['image']['tmp_name'];
$imgContent = addslashes(file_get_contents($image));
An insert for an employee details
// build query
$qry = "INSERT INTO employee VALUES(" .
"'$empnum','$lastname','$firstname'," .
"'$initial','$job'," .
"'$username',PASSWORD('$password'),' $emp_bdate',' $imgContent')";
}
// execute query
$added = mysqli_query($dbconn,$qry);
This is to check if there is any error
// report results
if(trim($added) != "")
echo "Record added successfully." . "<br>";
else
{
echo "ERROR: Record could not be added<br>" .
mysqli_error($dbconn);
}
// close connection
mysqli_close($dbconn);
}
?>
I am outputting am image as below though no image displayed
$imageData =base64_encode($line['image']);
echo "<img src='data:image/jpeg;base64,$imageData' height='200' width='250' alt=''>'"
Don't save image file as base64, you just save where image dir place. So when you call image just call the url to image dir place.
try this code, make sure your image extension is always "jpeg" or you need to make it dynamic.
<?php
$imageData = base64_encode($line['image']);
echo "<img src='data:image/jpeg;base64,$imageData' height='200' width='250'>";
?>