如何在数据库中回显存储为blob的图像?

时间:2013-02-01 12:24:46

标签: php mysql image blob echo

我只是想知道PHP代码是什么来回显我存储在数据库的特定表中的图像。

3 个答案:

答案 0 :(得分:2)

嗯,这是你想要的图像的HTML:

<img src="image_render.php?image_id=4" /> <!-- or any unique identifier for that image -->

image_render.php中,您需要执行以下操作:

// get the image information base on the unique identifier passed in the URL
 header("Content-Type: image/png"); // tell the browser that this is an image
 echo $imageBlog; // this is what you took from the database

确保您不在此文件中添加额外的输出,否则事情会变坏。

就是这样。

注意

在大多数情况下,将图像位置简单地存储在服务器而不是整个图像上会更好/更快,因此在做出此决定之前,您可能需要更多地记录自己。

以下是关于advantages and disadvantages of storing images in the databaseanother one here

的讨论 祝你好运!

答案 1 :(得分:0)

我希望echo html_entity_decode($ blobfield)可以帮助您在使用任何编辑器上传图像时编写图像。

答案 2 :(得分:0)

根据SO上的answer上的另一个similar topic

echo "<dt><strong>Technician Image:</strong></dt><dd>" . 
 '<img src="data:image/jpeg;base64,'.
  base64_encode($row2['image']).
  '" width="290" height="290">' . "</dd>";

*尝试在发布前进行搜索。