显示 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
Show a BLOB image PHP MySQL along with other data
提问by Sudantha
I have some data stored in a MySQL
database .. i would like to show the stored image data along with otherdata in a .php
page..
我有一些数据存储在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 Joe Phillips
回答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) . '"/>