我的 PHP 代码如下 回显图像仅显示其缩略图
<?php
if(isset($_SESSION['user_id'])){
$userid = $_SESSION['user_id'] ;
$query = "SELECT img FROM user where iduser='{$userid}' LIMIT 1 ";
$result_set = mysqli_query($connection,$query);
while($row = mysqli_fetch_assoc($result_set)){
echo $row['img'];
if(is_null($row['img'])){
echo '<img src="assets/images/fuser.png" class="img-responsive img-thumbnail" style="height:256px;width:256px">';
}else{
echo '<img src="assets/images/"'.$row['img'].'" class="img-responsive img-thumbnail" style="height:256px;width:256px">';
}
}
}
?>
我的图片是这样的 https://imgur.com/a/uXcdytz
最佳答案
您回显的 html 格式不正确:
echo '<img src="assets/images/"'.$row['img'].'" class="img-responsive img-thumbnail" style="height:256px;width:256px">';
对于 $row['img']
即 image1.jpg
,您的代码将回应:
<img src="assets/images/"image1.jpg" class="img-responsive img-thumbnail" style="height:256px;width:256px">
它在 src
属性中有一个额外的不必要的引号,因此图像 src
目标将不存在,您的回显应该是(在删除 之后)
在 images/
之后:
echo '<img src="assets/images/'.$row['img'].'" class="img-responsive img-thumbnail" style="height:256px;width:256px">';
还要确保您的 php 文件位于文件夹 assets/
中。
关于php - 为什么 php 回显图像只显示图像的缩略图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50574133/