头(& # 39;内容类型:图像/ jpeg # 39;)


header('Content-Type: image/jpeg')

这个编码给了我麻烦。我想显示所有的图像从数据库PHP请帮助

header("Content-Type: image/jpeg");
$con = mysql_connect("localhost", "admin", "test") or die('Could not connect to server');
mysql_select_db("myweb", $con) or die('Could not connect to database');
$query = "SELECT * FROM photos";
$result = mysql_query($query);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$pic = $row['pic'];
echo $pic;

你需要一些时间和img标签。

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
    $pic = $row['pic'];
?>
<img src="<?= $pic ?>"></img>
<?php } ?>

差不多。

在这个答案中,我认为数据库只包含图像的url。

如果你要在上面使用HTML,你的页面的Content-Type不应该是image/jpeg。

同时,停止使用mysql_*,开始使用mysqli_*PDO