gpt4 book ai didi

php - 从数据库检索图像但没有显示任何内容

转载 作者:行者123 更新时间:2023-11-29 17:56:03 25 4
gpt4 key购买 nike

我有一个表单,通过该表单我可以将图像提交到数据库(我 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> " ;

}
?>

最佳答案

我做了一些调整,这是正确的答案:

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

(不需要 header("Content-type: image/jpg");)

关于php - 从数据库检索图像但没有显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48831234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com