当前位置:首页 > 数据库 > SQlite

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

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

我正在尝试

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

表结构

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

但是当我putheader(‘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'];?>'/>

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!