从数据库中检索图像但没有显示

时间:2018-02-16 16:41:15

标签: php html mysql

我有一个表单并且使用此表单我将图像提交到数据库(我100%确定此表单运行良好且图像在数据库中正确存储) 但是当我试图检索并向他们展示没有任何事情发生时。

<!-- index.php -->
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="fa/font-awesome-4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/bootstrap/bottons/bootstrap.css">
    <link rel="stylesheet" href="css/index.css">
    <title> index.php </title>
</head>
<body>
    <div class="product-row">
        <?php include('showimages.php'); ?>
    </div>
</body>
</html>


---------showimages.php :----------------       
<?php
    $db = mysqli_connect('localhost', 'root', '', 'online_shopping');
    $last_id = mysqli_insert_id($db);
    $query = "SELECT * FROM products ORDER BY productID desc limit 8;"  ;   
    $result = mysqli_query($db, $query);
    header("Content-type: image/jpg");
    while($row = mysqli_fetch_assoc($result)) {             
        echo "<div class='each-product'>
            <div class='product-image' style='background-image: url(".$row['pric1'].")'>
            </div>                 
            <i class='fa fa-heart-o' aria-hidden='true'></i>
            <div class='name'>".  $row['name'] ." </div>
            <div class='price'>" .$row['price'].  "<span class='toman'> dollar </span> </div>
            <div class='add-to-basket'>
                <button type='button' class='btn btn-lg btn-success'> <i class='fa fa-shopping-basket' aria-hidden='true'></i>  add to basket </button>
            </div>
        </div> " ;

    }
?>

1 个答案:

答案 0 :(得分:0)

我做了一些调整,这是真实的答案:

<div class='product-image' style='background-image: url(data:image/jpeg;base64,".base64_encode($row['pric1'])."')'>
</div>

(不需要标题(&#34;内容类型:image / jpg&#34;);)