从表中获取blob图像并使用php sqlite3显示它


Fetch blob image from table and display it using php sqlite3

我知道这个问题已经被问过很多次了,但我无法使用任何一个解决这个问题。我是sqlite的新手,不明白我做错了什么。

我在尝试什么

我正在尝试创建个人资料视图页面。我能够从我的sqlite数据库中获取所有细节,但我无法显示我的个人资料图片。

表结构
    **username|landline|mobile|email|profilepicture**
         john |xxxxxxxx|xxxxxx|x@x.x|blob

WHAT I TRIED

  $sql = "SELECT * FROM profile";
  $query = $db->query($sql);
  while($row = $query->fetchArray(SQLITE3_ASSOC) ){
  echo "NAME = ". $row['user_name'] . "<br/>";
  echo "LANDLINE = ". $row['user_landline'] ."<br/>";
  echo "MOBILE = ". $row['user_mobile'] ."<br/>";
  echo "EMAIL =  ".$row['user_email'] ."<br/>";
  header('Content-Type: image/png');
  echo $row['user_profile_picture'];
  }

  <html>
  <img src='profile.php?imgid=<?php echo $row['user_profile_picture'];?>'/>
  </html>

但是当我输入header('Content-Type: image/png');

时,图像不显示,其他数据也不显示。

创建image.php:

<?php 
$sql = "SELECT user_profile_picture FROM profile WHERE id = " . $_GET['id'];
$query = $db->query($sql);
$row = $query->fetchArray(SQLITE3_ASSOC);
header('Content-Type: image/png');
echo $row['user_profile_picture'];
在profile.php:

<img src='image.php?id=<?php echo $row['id'];?>'/>