【问题标题】:Fetch blob image from table and display it using php sqlite3从表中获取 blob 图像并使用 php sqlite3 显示它
【发布时间】:2013-06-02 00:42:25
【问题描述】:

我知道这个问题已被问过很多次,但我无法使用其中任何一个来解决这个问题。 我是 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>

但是当我输入header('Content-Type: image/png');时,图像不显示,其余数据也不显示

【问题讨论】:

    标签: php sqlite blob


    【解决方案1】:

    创建一个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'];?>'/>
    

    【讨论】:

    • '/> 这是什么意思。主要是什么id
    • 我假设您的表中有一个 id 列(主键)。
    • 只有图片是png才支持吗?
    • 不行,上传时也可以将图片类型存入数据库。
    猜你喜欢
    • 2017-01-26
    • 1970-01-01
    • 2020-08-29
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    相关资源
    最近更新 更多