【问题标题】:why php echoed image shows only thumbnail of the image?为什么 php echoed image 只显示图像的缩略图?
【发布时间】:2018-11-07 12:08:06
【问题描述】:

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

【问题讨论】:

  • 你正在使用 Bootstrap 的 img-thumbnail 类!
  • 是的..但这不是原因..我删除了该类并再次尝试..但仍然遇到同样的问题。只需检查下面的链接imgur.com/a/uXcdytz
  • 这意味着图片的来源(src)有问题,看来问题出在你的回显字符串中,请参阅我的答案进行解释。

标签: php html css bootstrap-4


【解决方案1】:

您回显的 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/ 中。

【讨论】:

    猜你喜欢
    • 2012-04-18
    • 1970-01-01
    • 2011-10-16
    • 2020-07-24
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    相关资源
    最近更新 更多