当我尝试显示数据库中的图像时,图像未显示,不知道问题是什么,这是我的代码。
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);
}
?>
显示.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++;
}
?>
谁能帮我解决这个问题吗?
最佳答案
- 您的
display.php
似乎没有产生正确的<img>
标签。 - 检查数据库中的 img 字段是否标记为
BINARY
关于php - 无法显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3124047/