【发布时间】:2013-01-16 18:19:35
【问题描述】:
我只是想知道 PHP 代码是什么来回显我存储在数据库的特定表中的图像。
【问题讨论】:
-
你是保存在数据库中的图片路径还是图片数据?
-
http://stackoverflow.com/questions/5525830/displaying-an-image-stored-in-a-mysql-blob
我只是想知道 PHP 代码是什么来回显我存储在数据库的特定表中的图像。
【问题讨论】:
http://stackoverflow.com/questions/5525830/displaying-an-image-stored-in-a-mysql-blob
嗯,这是你想要的图片的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 database和another one here的讨论。
祝你好运!
【讨论】:
如果使用任何编辑器上传图像,我希望 echo html_entity_decode($blobfield) 可以帮助您编写图像。
【讨论】:
根据另一个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>";
*发帖前一定要搜索一下。
【讨论】: