PHP从数据库检索图像错误

PHP从数据库检索图像错误,php,database,mysqli,Php,Database,Mysqli,我正在尝试从数据库中调用图像。我已经建立了正确到达数据库的图像,但是当我向下拉图像时,我会得到组成它的Blob文本。如何下拉图像以显示图像 <?php //libs include 'library/config.php'; include 'library/opendb.php'; //query $query = "SELECT * FROM `upload` WHERE `postID`=".$elem["postID"].";"; $

我正在尝试从数据库中调用图像。我已经建立了正确到达数据库的图像,但是当我向下拉图像时,我会得到组成它的Blob文本。如何下拉图像以显示图像

<?php
    //libs
    include 'library/config.php';
    include 'library/opendb.php';
    //query
    $query = "SELECT * FROM `upload` WHERE `postID`=".$elem["postID"].";";
    $result = mysqli_query($conn, $query);
    if (mysqli_num_rows($result) > 0) { // if results exist
        while ($row = mysqli_fetch_assoc($result)) { // assign db cont to variable
            $name = $row["name"];
            $size = $row["size"];
            $type = $row["type"];
            $content = $row["content"];
            // header info
            header("Content-length: $size");
            header("Content-type: $type");
            header("Content-Disposition: attachment; filename=$name");
            //display image
            echo "img", $content;
         }
         include 'library/closedb.php';
     ?>

使用

显示jpeg图像


您在mysql中有BLOB数据类型?可能重复的可能重复的
   $content = base64_encode($_row['content']);
$code_base64 = $row['content'];
$code_base64 = str_replace('data:image/jpeg;base64,','',$code_base64);
$code_binary = base64_decode($code_base64);
$image= imagecreatefromstring($code_binary);
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);