繁体   English   中英

当文件夹/ DB中的图像时如何使用PHP显示图像

[英]How to display images using php when images in folder / DB

我的本地主机上有一个DB,其中的一个表包含属于各种类别(image_category)的图像。 图像包含在一个文件夹中, ie: /gallery/xxxIMAGESxxx我将hmtl代码保留在其中的php文件高出一步的位置,以便在用户屏幕上显示。

现在我面临的唯一问题是,当我想在网站上显示图像时,它们不会显示。 取而代之的是,我仅获得图像的标题和说明,这些标题也来自数据库。

在我的锚标签的样式部分中,我加入了

background-image: url(gallery/'.$row["imgFullNameGallery"].')">

图片应显示的位置。

我认为这与Base64编码有关,但是我无法指出应该在何处以及如何编码/设置语法。 如果这是问题所在。

帮助将不胜感激。 提前谢谢。

//this is the php code with the call to the table with the images

<div class="display_CNC_Machining_images">
    <?php
    include_once 'includes/dbh.inc.php';

    $sql = "SELECT * FROM gallery WHERE image_category = 'CNC_Machinery'";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt,$sql)) {
      echo 'SQL statement failed!';
    } else {
      mysqli_stmt_execute($stmt);
      $result = mysqli_stmt_get_result($stmt);

      while ($row = mysqli_fetch_assoc($result)) {


//what's echoed out by the database

        echo '  <a class="images" style="background-repeat:no-repeat; background-image: url(gallery/'.$row["imgFullNameGallery"].')">
                <div class="color-overlay">
                <h3>'.$row["titleGallery"].'</h3>
                <p>'.$row["descGallery"].'</p>
                </div>
                </a>';
      }
    }
    ?>
</div>

预期结果:

将显示来自DB / localfolder的图像以及来自DB的图像标题和图像描述。

实际结果:

仅显示来自DB的图像标题和图像描述。

带有图像的数据库

目前显示在我的屏幕上,没有img

而不是这样做:

echo '<a class="images" style="background-repeat:no-repeat; background-image: url(gallery/'.$row["imgFullNameGallery"].')">
<div class="color-overlay">
<h3>'.$row["titleGallery"].'</h3>
<p>'.$row["descGallery"].'</p>
</div>
</a>';

做这个:

$image = $row["imgFullNameGallery"];
echo '<a class="images" style="background-repeat:no-repeat; background-image: url(gallery/'.$image.')">
<div class="color-overlay">
<h3>'.$row["titleGallery"].'</h3>
<p>'.$row["descGallery"].'</p>
</div>
</a>';

$row["imgFullNameGallery"]放入一个$row["imgFullNameGallery"]的变量将防止冲突。
双引号将与样式中的引号冲突。
这应该显示图像。
还要检查您的图像是否存在于文件夹中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM