gpt4 book ai didi

php - 无法使用 php 显示 MySQL 数据库中的图像

转载 作者:行者123 更新时间:2023-11-29 13:43:34 28 4
gpt4 key购买 nike

我有一个 Products_Images 表,它以 BLOB 格式存储图像。我想在“查看所有产品”页面中显示所有图片和产品详细信息。为了完成此任务,我创建了以下程序,但它没有给我所需的输出。请检查一下。

谢谢。

<?php

include 'connect.php';

$query= "select distinct product_id, image from product_images";

$query_run= mysql_query($query);

while ($query_fetch= mysql_fetch_assoc($query_run))
{




echo '</br>';
echo $query_fetch['image'];


}

header("Content-type: image/jpeg");





?>

显示图像

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<br />
<img src="all_images.php" alt="Image" width="50" height="50" />
<body>
</body>
</html>

最佳答案

当您使用 header() 函数时,您无法在 header 调用之前打印任何内容,因为这会指示 Web 服务器准备内容 header

<?php

include 'connect.php';

$query= "select distinct product_id, image from product_images";

$query_run= mysql_query($query);

header("Content-type: image/jpeg");
while ($query_fetch= mysql_fetch_assoc($query_run))
{




// echo '</br>';
echo $query_fetch['image'];


}

?>

Note: Please avoid using mysql* they are depreciated in php newer version keep your hands on using PDO or at least mysqli

关于php - 无法使用 php 显示 MySQL 数据库中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17760703/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com