Fetch blob image from table and display it using php sqlite3

两盒软妹~` 提交于 2019-12-02 04:27:32

问题


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.

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.

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 putheader('Content-Type: image/png');


回答1:


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'];

In profile.php:

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


来源:https://stackoverflow.com/questions/16954772/fetch-blob-image-from-table-and-display-it-using-php-sqlite3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!