简体   繁体   中英

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

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

Well, here is the html you want for the image:

<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:

// 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,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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