php - 为什么 php 回显图像只显示图像的缩略图?

标签 php html css bootstrap-4

我的 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/

相关文章:

php - 对具有数百万条记录的 2 个表进行连接速度更快

php - 表单提交未将数据输入数据库

javascript - 显示消息而不重新加载 html 页面

javascript - 使用 Soundcloud 播放器按钮更改嵌入的页面上的元素

javascript - 选择具有相似类名但没有 div id 的 div

javascript - JQuery onClick 和 HTML

php - 通过引用传递函数

php - 如何将 MySQL 表转储到文件然后读取它并使用它代替数据库本身?

javascript - CSS 动画不能与内联显示属性一起使用吗?

html - <a> 标签小于子标签