could not display image
When i'm trying to display the image from the database the image is not been displayed didn't know what was the problem,here is my code.
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++;
}
?>
can anyone please help me with this?
- Your
display.php
doesn't seem to produce proper<img>
tags. - Check that your img field in the database is marked as
BINARY
i thing you use image data type as BLOB
Why are you strong images into the database? It is better idea to simply save the name/path of the images into the database, upload them to a folder and show them while retrieving their name in <img>
tags.
精彩评论