【问题标题】:Displays an image from the database, Picture does not Show using php显示数据库中的图像,使用 php 不显示图片
【发布时间】:2017-08-24 14:30:13
【问题描述】:

晚上好专家 :),我正在学习使用 php 从数据库中显示图像,我遇到了问题。没有错误信息,但图像不显示,请帮助。

这是我的代码headline.php:

<?php
include 'koneksi.php';

$tabel = 'isiberita';
$sql=$conn->query("SELECT * from $tabel order by tanggal desc limit 3");
  while ($tampil = $sql->fetch(PDO::FETCH_ASSOC)) {
    echo "<p align='justify>'";
    echo "<img src='$tampil[gambar]' aligen='left'>";
    echo "<font valign='top'>";
    echo "<strong>";
    echo $tampil['judul'];
    echo "</strong>";
    echo $tampil['tanggal'];
    $data=substr($tampil['isi'],0,200);
    echo $data;
    echo "<a href='index.php?menu=detail_headline&id=$tampil[id_berita]'>&nbsp; baca lengkap>>>></a>";
    echo "</font></p><br>";
  }

?>

这是我的图片目录: C:\xampp\htdocs\portalberita\gambar

这是我的 header.php 目录: C:\xampp\htdocs\portalberita

This my value database :

This output :

【问题讨论】:

  • 检查输出的实际 HTML。 img 元素是什么?这是你所期望的吗?当您的浏览器请求该图像时,服务器的响应是什么?

标签: php mysql database image phpmyadmin


【解决方案1】:

要在&lt;img&gt; 标签中显示来自目录的图像,您必须指定图像路径和名称,例如:

<img src="/images/imagename.ext">  <!-- If image folder exist on the same path where the code file exists -->

<img src="../images/imagename.ext">  <!-- If image folder exist one level up where the code file exists -->

所以检查image 文件夹和您的代码目录并相应地修复路径。

【讨论】:

    【解决方案2】:

    尝试替换

    echo "<img src='$tampil[gambar]' aligen='left'>";
    

    echo '<img src="' . $tampil['gambar'] . '" align="left" />';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-07
      • 2021-09-07
      • 2016-04-14
      • 2015-06-21
      • 1970-01-01
      • 2018-04-29
      • 2020-06-22
      相关资源
      最近更新 更多