如何显示使用php上传到我的数据库的LONGBLOB图像

时间:2018-01-09 04:32:57

标签: php database

此代码显示一串符号,而不是显示上传的图像
    

session_start();
include 'connection.php';
$id=$_SESSION["id"];

if (!isset($_SESSION['id'])) {
header("location:login.php"); 
}

?>

<?php

//DB Details
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPass = 'password';
$dbName = 'images';

//Create connection and select DB
$db = new mysqli ($dbHost, $dbUsername, $dbPass, $dbName);

检查数据库连接

if ($db->connect_error) {
    die ("Connection Failed: " . $db->connect_error);
    }

//Get image data from database
$result = $db->query("SELECT image From images Where user_id=$id");

if ($result->num_rows > 0){
    $imgData = $result->fetch_assoc();

这是渲染图像

    header("Content-type: image/jpeg");
    echo $imgData['image'];
}else{
    echo "Image not found...";
}
?>

当我尝试查看上传的图像时,它会显示一些符号

0 个答案:

没有答案