无法在图片代码中显示longblob

时间:2015-12-14 14:53:23

标签: php database pdo blob

我一直在努力解决这个问题好几个小时了。页面应该显示存储为longblobs的数据库中的图像列表,但它只是向我显示每个图标的“img”图标。对我能做什么的任何建议?

showImage.php

<?php
include_once('connection.php');

$sql = "SELECT filetype, picture FROM postcards WHERE ID=". $_GET['ID'];

$rows=$conn->query($sql);
foreach ($rows as $row) {
    header("Content-type: ". $row["filetype"]);
    echo $row["picture"];
}

$conn=null;

?>

listImage.php

<?php include_once('connection.php'); ?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="uft-8">
        <title>List database content</title>
    </head>

    <body>

        <?php

            $sql = "SELECT * FROM postcards";
            $rows=$conn->query($sql);

            foreach ($rows as $row) {
                echo '<p>Upload by person: '.$row["title"].'</p>';
                echo '<p><img src="showimage2.php?ID='.$row["ID"].'"></p>';
            }

            $conn=null;
        ?>

    </body>

</html>

connection.php

<?php
    $dsn = "mysql:host=localhost;dbname=tellastory";
    $username="root";
    $password="";
    $e="";

    try {
        $conn = new PDO($dsn, $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch (PDOException $e) {
        echo "Connection failed: " . $e->getMessage();
    };
?>

提前致谢!

0 个答案:

没有答案