i need some help i'm trying to insert a image in database and retrieve (longbool)

i have inserted the image in the form of boolean format but while retrieving i’m getting a error

" Trying to access array offset on value of type bool in …"

code:

<?php

require_once "pdo.php";

$_query="SELECT * FROM tbl_images ORDER BY id DESC";

$all_profiles = $pdo->query($_query);

while ( $row = $all_profiles->fetch(PDO::FETCH_OBJ) )

{

$profiles[] = $row;

}

?>

<html>

...

<body>

...

<?php if (empty($profiles))

{

echo'<p>No rows found</p>';

}

else

{

foreach($profiles as $profile)

{

echo '

<div class="col-lg-4 col-md-6 mb-5">

<a href="data:image/jpeg;base64,'.base64_encode($row['name'] ).'" class="d-inline-block">

<img src="data:image/jpeg;base64,'.base64_encode($row['name'] ).'" alt="Image" class="img-fluid">

</a>

<h3 style="color: #fff" > '; echo $profile->description ;'</h2>

</div>

';

}

}

?>

...

</body>

</html>

For anyone to help you with this we’ll need the complete error message, and the details of your database.

Well, you normally do not save images in databases. The overhead it too high and the extra processing needed can overwhelm server resources. Normally, you would save the file in a folder and save the name in the database to be used as a pointer to the image.

Now with that said, you can not ENCODE when pulling out a base64 object. You save it using ENCODE and then when you display it, you use DECODE. The base64 is a format that encodes HEX data from the raw data in the image file and turns it into 64 bit characters that the database can save and retrieve.
The ENCODED data is stored into your database using a BLOB or TEXT field. And, then, you DECODE the stored data when needed.

Hope that helps…

On second thought, perhaps you really want to display base64 image? If so, you would do it this way:

<img style='display:block; width:100px;height:100px;' id='base64image'                 
       src='data:image/jpeg;base64, LzlqLzRBQ...<!-- base64 data -->' />

The data as you see in this example is base64, but in your example you are creating a link not an image. Very mixed up code…

Sponsor our Newsletter | Privacy Policy | Terms of Service