Show a BLOB image PHP MySQL along with other data

2020-02-05 11:13发布

I have some data stored in a MySQL database .. i would like to show the stored image data along with other data in a .php page..

if i fetch data from the database and use header("Content-type: image/jpeg"); its not possible to show the image with other php data.. is there a a other way ?

标签: php mysql blob
3条回答
The star\"
2楼-- · 2020-02-05 11:51

It depends how you stored you data, but sometimes you have to convert the data to base64. Try this

echo '<img src="data:image/png;base64,' . base64_encode($blob_data) . '"/>
查看更多
我只想做你的唯一
4楼-- · 2020-02-05 12:01

If you set the header to image/jpeg that treats your entire page as an image file.. You want the data to be insert into the image holder only.

Try something like this

<img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />

Where you will next echo the blob data into the image src

 <img alt="Embedded Image" src="data:image/png;base64,<?php echo $image->blob_data; ?> "/>
查看更多
登录 后发表回答