Php 我无法显示从数据库提取的图像。它显示HTML代码而不是图片

Php 我无法显示从数据库提取的图像。它显示HTML代码而不是图片,php,html,image,mysqli,Php,Html,Image,Mysqli,我使用以下方式将图片上载到数据库: new.php: <form action="<?php echo base_url(); ?>index.php/hen/insert" method="post" enctype="multipart/form-data"> <input type="file" name="image1"> 到目前为止,一切都很好。我看到使用longblob类型在数据库上成功地将图像上载到DB上 但当我想在另一页上显示图像时,请使用

我使用以下方式将图片上载到数据库:

new.php:

<form  action="<?php echo base_url(); ?>index.php/hen/insert" method="post" enctype="multipart/form-data">
<input type="file" name="image1">
到目前为止,一切都很好。我看到使用longblob类型在数据库上成功地将图像上载到DB上

但当我想在另一页上显示图像时,请使用:

mysqli_select_db($conn,"hen" );
$id =$_REQUEST['id'];
$U=$_REQUEST['U'];
if ($U=="Supervisor"){
// sending query
$s=mysqli_query($conn,"SELECT * FROM `hen` WHERE `hen`.`HenNumber` = '$id'");   


echo "<table>";

 while($row=mysqli_fetch_array($s)){
     $data = base64_decode($row["image1"]);
     $im = imagecreatefromstring(file_get_contents($data));
     echo 'study ID: '.$row["0"];
     echo " <tr>";
      header("content-type :image/png");
    echo "<img border=\"0\" src=\"".$im."\" width=\"102\" alt=\"Your Name\" height=\"91\">";
    echo " </tr>";  


 }
 header("content-type :image/jpg");
 echo " </table>";  

我只看到html代码,而不是我的真实图片。

此时尝试发送内容类型标题毫无意义。如果您要输出单个图像的二进制图像数据以响应请求,则需要一个内容类型标头,但这根本不是您在这里要做的。当然,图像一开始并不属于数据库。正如您所看到的,我有headercontent类型:image/png;好的。正如我所说,这完全没有意义。不能在一个响应中混合使用不同类型的资源。您需要一个独立的脚本来输出一个图像的数据,并且只输出该图像;或者你需要内联二进制图像数据,关键字数据URI,关键字bad-idea-in-this-context。这很有帮助。我使用了一个单独的脚本,解决了这个问题。非常感谢。
mysqli_select_db($conn,"hen" );
$id =$_REQUEST['id'];
$U=$_REQUEST['U'];
if ($U=="Supervisor"){
// sending query
$s=mysqli_query($conn,"SELECT * FROM `hen` WHERE `hen`.`HenNumber` = '$id'");   


echo "<table>";

 while($row=mysqli_fetch_array($s)){
     $data = base64_decode($row["image1"]);
     $im = imagecreatefromstring(file_get_contents($data));
     echo 'study ID: '.$row["0"];
     echo " <tr>";
      header("content-type :image/png");
    echo "<img border=\"0\" src=\"".$im."\" width=\"102\" alt=\"Your Name\" height=\"91\">";
    echo " </tr>";  


 }
 header("content-type :image/jpg");
 echo " </table>";