显示 BLOB 图像 PHP MySQL 以及其他数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5932249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:56:34  来源:igfitidea点击:

Show a BLOB image PHP MySQL along with other data

phpmysqlblob

提问by Sudantha

I have some data stored in a MySQLdatabase .. i would like to show the stored image data along with otherdata in a .phppage..

我有一些数据存储在MySQL数据库中..我想在页面中显示存储的图像数据和其他数据.php..

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 ?

如果我从数据库中获取数据并使用header("Content-type: image/jpeg");它不可能用其他 php 数据显示图像..还有其他方法吗?

回答by Atticus

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.

如果将标题设置为将整个页面视为图像文件的 image/jpeg。您希望数据仅插入到图像持有人中。

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

接下来将 blob 数据回显到图像 src 中的位置

 <img alt="Embedded Image" src="data:image/png;base64,<?php echo $image->blob_data; ?> "/>

回答by Murolack

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

这取决于您如何存储数据,但有时您必须将数据转换为 base64。尝试这个

echo '<img src="data:image/png;base64,' . base64_encode($blob_data) . '"/>