【问题标题】:image doesn't display from database (MySQL/php)图像不从数据库中显示(MySQL/php)
【发布时间】:2021-09-07 18:53:35
【问题描述】:

所有内容都来自 PDO,并且显示良好,但图像除外。 我在数据库中写了文件夹的路径,就好像它是在 src=

之后写的一样

作为一个php初学者,我想知道它是否是显示图片的好方法

编辑: 图片为jpg格式, 控制台显示“404”,但路径很好

<?php
try {
    $bdd = new PDO(/*the pdo works*/);
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM equipepedagogique');//where the picture is
?>
 <div class="enseignants"><!--grid-->
            <!--case-->
            <?php 
            while ($donnees=$reponse->fetch())
            foreach ($donnees as $donnee) { 
                $img=$donnees['photo'];
                $nom=$donnees['name'];
                $prenom=$donnees['surname'];
                $fonction=$donnees['fonction'];?>
            <div class="enseignant">
                <a href="">
                    <img src="<?php echo $img?>" alt="" class="photoEnseignant">
                </a>
                <h1 style="margin-left:auto;margin-right:auto;"><?= $prenom .' '. $nom ?></h1>
                <p><?= $fonction ?></p>
            </div>
            <?php } ?>
        </div>

【问题讨论】:

  • $img 是路径还是二进制值?如果它是二进制值,则打印您从问题中的数据库中读取的示例值。
  • $img 包含什么内容?
  • $img 应该显示图片在数据库中的文件夹中的路径,存放的是 TEXT 类型。

标签: php mysql database image


【解决方案1】:
<?php
try {
    $bdd = new PDO(/*the pdo works*/);
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM equipepedagogique');//where the picture is
?>
 <div class="enseignants"><!--grid-->
            <!--case-->
            <?php 
            ***while ($donnees=$reponse->fetch())*** **//while($donnees=$reponse->mysql_fetch_array())**
            foreach ($donnees as $donnee) { 
                $img=$donnees['photo'];
                $nom=$donnees['name'];
                $prenom=$donnees['surname'];
                $fonction=$donnees['fonction'];?>
            <div class="enseignant">
                <a href="">
                    <img src="<?php echo $img?>" alt="" class="photoEnseignant">
                </a>
                <h1 style="margin-left:auto;margin-right:auto;"><?= $prenom .' '. $nom ?></h1>
                <p><?= $fonction ?></p>
            </div>
            <?php } ?>
        </div>

【讨论】:

  • 谢谢,但它不起作用。但是会显示 $nom、$prenom 和 $fonction
猜你喜欢
  • 2020-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-07
  • 2018-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多