我有这个 php 代码,它从数据库中获取二进制 (blob) 数据并在浏览器中显示为图像。但是,此后的所有内容都将被忽略。有没有办法让我也可以使用文本 queries/forms/tables
?同一页面上的基本 HTML 元素?
拥有一个只能显示来自数据库的图片而没有其他任何东西的页面对我来说毫无用处。
<?php
$mysqli=mysqli_connect('localhost','root','','draftdb');
if (!$mysqli)
die("Can't connect to MySQL: ".mysqli_connect_error());
$imageid= 1;
$stmt = $mysqli->prepare("SELECT PICTURE_ID FROM display WHERE INDEX_ID =?");
$stmt->bind_param("i", $imageid);
$stmt->execute();
$stmt->bind_result($image);
$stmt->fetch();
header("Content-Type: image/jpeg");
echo $image;
?>
最佳答案
不可以,每个页面只能有一个Content-Type
。
您应该做的只是创建另一个页面,其中包含图像(src 指向您显示的代码)和您要显示的表单,如下所示:
<html>
<body>
<div>
<img src="image.php" alt="image retreived from DB" />
</div>
<form>
<input type="text" name="foo" />
...
</form>
</body>
</html>
关于php - 我可以在同一页面上使用多个内容类型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11693202/