I'm working on a simple mobile app that uses a database to store content including images and I'm using ajax to request the information and display that information on the app. The problem that I'm having is that the image don't appears and I don't know why
This is the code that I'm using to store the information

$image = $_FILES['articleImg']['tmp_name'];
$date = date('l') .' '. date('d') . ', ' . date('Y');
$query = "INSERT INTO newsapp (title, company, category, details,
image, created) VALUES (:title, :company, :category, :details, :image, :created)";
$query_params = array(":title" => $_POST['title'],
":company" => $_POST['company'],
":category" => $_POST['category'],
":details" => $_POST['details'],
":image" => file_get_contents($image),
":created" => $date);
I have this file to that return the values in the database including the image:
$query = "SELECT id, title, company, category, details, image, created FROM newsapp";
try {
$stmt = $db->prepare($query);
$stmt->execute();
} catch (PDOException $ex) {
die ('Failed to run query: ' . $ex->getMessage());
}
$row = $stmt->fetchAll();
echo json_encode($row);
Ajax function;
var url = "getnews.php";
$.ajax({
type: "POST",
url: url,
crossDomain: true,
cache: false,
success: function(data)
$.each(JSON.parse(data), function(i, value)
{
console.log(value.title); // return value from database
console.log(value.image); // Return null
});
I have tryied to display the image by doing this, but it didn't work; Then I checked the value of image on the console and it says null
if try to display the image directly on php works fine.
echo '<img alt="blog" src="data:image/jpg;base64,'.base64_encode( $rows['image'] ).'"/>';
console.log(JSON.parse(data));to check what's in it?data:image/jpg;base64,and do your base64 encode in php or in the database with TO_BASE64. Or just encode it before storing.