【问题标题】:Image nut Read in Php from databaseImage nut 从数据库中读取 Php
【发布时间】:2017-02-26 02:03:02
【问题描述】:

当我从数据库中读取图片时,我遇到了这个问题。

显示如下:

这是我的代码:

<?php
include 'Header.php';
include 'yzd.php';
?>

<div class="container">
<h1> All Project </h1>
<?php
$posts = mysqli_query($db_connect,"select * from Project order by id desc");

while($post = mysqli_fetch_array($posts)){
    echo "
    <article>
    <a href='Project.php?id=$post[id]'>
    <h1>$post[NameProject]</h1>
    </a>
    <p class='text-muted']>
    <h3>$post[TypeProject]</h3>
    </p>
    <h4>$post[Description]</h4>

    $post[Pic];

    <p>-----------------------------------------------------------------------------</p>
    </article>";

}
?>

[![在此处输入图片描述][2]][2]

【问题讨论】:

  • 如果您要发布代码图像,不要指望太多帮助
  • 您好!好像你的问题写得不好。就目前而言,它只会吸引反对票,而没有答案。
  • 不要将实际图像存储在数据库中,存储它的位置。

标签: php database image


【解决方案1】:

尝试将原始图像输出转换为 base 64 数据 URI (see here) 你可以通过改变来做到这一点

$post[Pic]

进入

<img src='".'data:image/png;base64,' . base64_encode($post["Pic"])."'/>

鉴于您数据库中的所有图像都以 png(s) 格式存储,因此类型可能需要根据图像类型而有所不同。

以后请使用代码 sn-ps 而不是截图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-26
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    相关资源
    最近更新 更多