从表中获取Blob图片,并使用php sqlite3将其显示 [英] Fetch blob image from table and display it using php sqlite3

查看:94
本文介绍了从表中获取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'];?>'/>

这篇关于从表中获取Blob图片,并使用php sqlite3将其显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆