gpt4 book ai didi

php - 我正在尝试通过 PHP 在 HTML 文件中显示来自 MYSQL 的图像。我的代码有什么问题吗?

转载 作者:行者123 更新时间:2023-11-29 14:38:47 26 4
gpt4 key购买 nike

这是 PHP 代码。我基本上想做的是显示来自 mySQL 数据库的单个图像,但我似乎无法弄清楚它。

    <?php
$port = "****";
$server = "****".$port;
$dbname ="****";
$user = "****";

$conn = mysql_connect ("$server", "$user", "$pass") or die ("Connection
Error or Bad Port");

mysql_select_db($dbname) or die("Missing Database");

?>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Query 3</title>
</head>

<body bgcolor="white">


<hr>


<?php
$speakerPic = $_POST['speakerPic'];
$query = "SELECT speaker.speaker_picture FROM Speaker JOIN Contact USING(contact_id)
WHERE Contact.lname = ";
$query = $query."'".$speakerPic."';";
?>

<p>
The query:
<p>
<?php
print $query;
?>

<hr>
<p>
Result of query:
</p>

<?php
$row = mysql_fetch_array($query);
$content = $row['image'];

header('Content-type: image/jpg');
echo $content;
?>

</body>
</html>

这里什么不起作用?我真的很感谢你的帮助。

最佳答案

要在 HTML 文档中包含图像,您可以使用 <img>带有 src 的标签包含指向图像的 URI 的属性。

这可能是一个 HTTP URI(它可能会命中从数据库获取图像数据并返回它的 PHP 脚本),也可能是 DATA URI将图像直接编码到页面中。

处理图像的常用方法是将它们保存在文件系统上并将 URL(或可以从中构造 URL 的文件路径)存储在数据库中。

不能像现在尝试那样在另一个 HTTP 响应中间吐出一个 HTTP 响应。

关于php - 我正在尝试通过 PHP 在 HTML 文件中显示来自 MYSQL 的图像。我的代码有什么问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8431610/

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