简体   繁体   English

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

[英]How do I echo an image stored as a blob in my database?

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

Well, here is the html you want for the image: 好吧,这是你想要的图像的html:

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

in image_render.php you will want to do the following: 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

Make sure you don't add extra output in this file, or things will go bad. 确保你没有在这个文件中添加额外的输出,否则事情就会变坏。

That's about it. 就是这样。

Note 注意

In most situations it is better/faster to simply store the image location on the server instead of the whole image, so you probably need to document yourself a bit more before making this decision. 在大多数情况下,将图像位置简单地存储在服务器而不是整个图像上会更好/更快,因此在做出此决定之前,您可能需要更多地记录自己。

Here is a discussion about the advantages and disadvantages of storing images in the database , and another one here . 下面讨论在数据库中存储图像的优缺点另外还有一个

Good luck! 祝好运!

我希望echo html_entity_decode($ blobfield)可以帮助你编写图像,如果它是使用任何编辑器上传的。

According to another answer on a similar topic here on SO, 根据关于SO的类似主题的另一个答案

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

*Do try to search before posting. *在发布之前尝试搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM