如何在php中显示blob

时间:2018-05-23 18:59:23

标签: php phpmyadmin blob

<?php
    try{
        include("dbconnectie.php");
        $query = $db->prepare("SELECT * FROM shop WHERE id_img = '2'");
        $query->execute();
        $result = $query->fetchALL(PDO::FETCH_ASSOC);
        echo "<table>";
            foreach($result as &$data) {
                echo "<tr>";
                    echo "<td>" . $data["brand"] . "</td>";
                    echo "<td>" . $data["model"] . "</td>";
                    echo "<td>" . $data["cond"] . "</td>";
                    echo "<td>" . $data["price"] . "</td>";
                    echo '<img src="data:image/png;base64,'.base64_encode($blob).'"/>';
                echo "</tr>";
            }
        echo "</table>";
    } catch(PDOException $e) {
        die("Error!: " . $e->getMessage());
    }
?>

所以我设法在phpmyadmin数据库中将文件保存为longblob,但问题是我不知道如何显示它。请帮忙

2 个答案:

答案 0 :(得分:5)

而不是使用$blob尝试从数据库中调用图像字段名称。

echo '<img src="data:image/png;base64,'.base64_encode( $data["image"] ).'"/>';

答案 1 :(得分:0)

在您提供的代码中,未定义$blob。也许你打算写:

echo '<img src="data:image/png;base64,' . base64_encode($data['blob']) . '">';