【问题标题】:How do I echo an image stored as a blob in my database?如何回显在我的数据库中存储为 blob 的图像?
【发布时间】:2013-01-16 18:19:35
【问题描述】:

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

【问题讨论】:

  • 你是保存在数据库中的图片路径还是图片数据?
  • http://stackoverflow.com/questions/5525830/displaying-an-image-stored-in-a-mysql-blob

标签: php mysql image blob echo


【解决方案1】:

嗯,这是你想要的图片的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的讨论。

祝你好运!

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      根据另一个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>";
      

      *发帖前一定要搜索一下。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-16
        • 2017-08-19
        • 2012-10-24
        • 2011-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多