简体   繁体   English

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

[英]Fetch blob image from table and display it using php sqlite3

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 的新手,无法理解我做错了什么。

WHAT I AM TRYING我在尝试什么

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.我可以从我的 sqlite 数据库中获取所有详细信息,但我无法显示我的个人资料图片。

TABLE STRUCTURE表结构

    **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>

But the image dosenot show and also the rest of the data dosenot display when i put header('Content-Type: image/png');但是当我放置header('Content-Type: image/png');时,图像不显示,其余数据也不显示header('Content-Type: image/png');

Create an image.php:创建一个 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'];

In profile.php:在 profile.php 中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM