我知道这个问题已被问过很多次,但我无法使用其中任何一个来解决这个问题。 我是 sqlite 的新手,无法理解我做错了什么。
我正在尝试什么
我正在尝试制作个人资料查看页面。我可以从我的 sqlite 数据库中获取所有详细信息,但无法显示我的个人资料图片。
表结构
**username|landline|mobile|email|profilepicture**
john |xxxxxxxx|xxxxxx|<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1c9f1c99fc9" rel="noreferrer noopener nofollow">[email protected]</a>|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:
<?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'];?>'/>
关于php - 从表中获取 blob 图像并使用 php sqlite3 显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16954772/