当我试图从数据库显示图像时,图像没有显示,不知道是什么问题,这是我的代码。
show_desc.php
<?php
$errmsg = "";
if (! @mysql_connect("localhost","root","")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("dbname");
if (isset($_GET['img_name'])) {
$gotten = @mysql_query("select img from image where img_id = ".$_GET['img_name']);
header("Content-type: image/x-ms-bmp");
while ($row = mysql_fetch_array($gotten)) {
print $row['img'];
}
mysql_free_result($gotten);
}
?>
Display.php的
<?php
$errmsg = "";
if (! @mysql_connect("localhost","root","")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("dbase_mgb");
$strSQL = "select * from image";
$rsPix = mysql_query($strSQL);
$numRows = mysql_numrows($rsPix);
$i = 0;
while($i < $numRows) {
?>
<image src="show_desc.php?img_id=<?php echo mysql_result($rsPix,$i,"img_id"); ?>"
<?php
$i++;
}
?>
任何人都可以帮我这个吗?
答案 0 :(得分:1)
display.php
似乎无法生成正确的<img>
代码。BINARY
答案 1 :(得分:1)
我使用图像数据类型作为BLOB
答案 2 :(得分:0)
为什么你有强大的图像进入数据库?最好只需将图像的名称/路径保存到数据库中,将它们上传到文件夹并在<img>
标签中检索其名称时显示它们。