0

I have stored several images in mediumblob type on a SQL database , I have tired following code but it gives ASCII characters instead of images

    while($obj = $results->fetch_object())
      {
 echo ' <div class="col-md-3"> ';
 echo ' <h2>'.$obj->name.'</h2>';
 echo ' <img src=Image/'.$obj->pic.' />';
 echo ' <div class="row">'.$obj->price.'</div>';
 echo ' </div> ';
      }

how do I change this to appear an image?

echo ' <img src=Image/'.$obj->pic.' />';

I know it's not a good practice to store images inside databases.

Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

0

The format you would probably want to try is more like ( assuming the data in the pic column is already base64 encoded )

echo "<img src='data:image/jpeg;base64, {$obj->pic}' /> ";
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
0

This worked for me !

  echo '<img src="data:image/x-icon;base64,'.base64_encode($obj->pic).'"> ';