如何显示存储在MySQL数据库中的图像?

时间:2011-02-26 07:26:56

标签: php mysql image

我在MySQL表中有一些jpg图像。如何显示这些图像?

有人可以通过提供示例代码来帮助我吗?

2 个答案:

答案 0 :(得分:2)

<?php 
$image = $row['myimage']; 
header("Content-type: image/gif");
print $image; 
exit; 
>?

但是存储路径似乎更容易......

答案 1 :(得分:0)

这个概念有点类似于下面的代码,其中img1.jpg是一个图像文件

$handle = fopen('img1.jpg', 'r');

header("Content-type: image/gif");//make sure that you dont have output before it

echo fread($handle, filesize('img1.jpg'));

尝试下一个实验

$handle = fopen('img1.jpg', 'r');

echo fread($handle, filesize('img1.jpg'));
//If you are storing the output of this in
//your db then this should work
//however it is best recommended to store 
//path which makes you jog a lot easir

//if you get the same error then you have error in 
//storing your file