从表中获取Blob图片,并使用php sqlite3将其显示

从表中获取Blob图片,并使用php sqlite3将其显示

问题描述:

我知道这个问题已经被问过很多次了,但是我无法使用其中任何一个来解决. 我是sqlite的新手,无法理解我在做什么错.

I know this question has been asked many times but I couldnot solve this using any of them. I am new to sqlite and cannot understand what I am doing wrong.

我正在尝试创建个人资料查看页面.我可以从sqlite数据库中获取所有详细信息,但无法显示个人资料图片.

I am trying to make a profile view page. I am able to fetch all details from my sqlite database but i am not able to display my profile picture.

    **username|landline|mobile|email|profilepicture**

         john |xxxxxxxx|xxxxxx|x@x.x|blob

我尝试过的东西

  $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:

Create an 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中:

In profile.php:

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