在我的数据库中,图像(jpeg,bmp格式)存储在bytea数据类型中,以数据库中的二进制代码显示。现在我想从数据库中检索图像。但我无法在网页中获取图像。当我使用下面给出的代码进行检索时,它显示了二进制代码值(即数字,字符,符号的组合)。我的代码是如何从数据库中检索图像?
$dbconn = pg_connect("host=localhost user=xxxx password=xxxx dbname=xxxx")
or die('Could not connect: ' .pg_last_error());
$rs = pg_query($dbconn, "select scan_image from image where cno='4' and imageno='1'");
$image = pg_escape_bytea(pg_fetch_result($rs, 0));
echo $image;
我是否正确使用此代码?请帮我找到解决方案。
+1,只记得使用正确的内容类型,为每个类型的图像(PNG,GIF,JPG,BMP) – Strae 2010-02-25 07:42:09