图像不';t使用PHP显示

图像不';t使用PHP显示,php,Php,我正在尝试显示数据库中的内容。下面的查询工作正常,但问题是图像不再显示 <?php session_start(); // Include config file require_once "../auth/dbconnection.php"; $output=''; $sql='select `image`,`title`,`sub_title`,`username`,`blog_id`,`body`,`published` from `blog` WH

我正在尝试
显示
数据库中的内容。下面的
查询
工作正常,但问题是
图像
不再显示

<?php
session_start();

// Include config file
require_once "../auth/dbconnection.php";

$output='';
    
$sql='select `image`,`title`,`sub_title`,`username`,`blog_id`,`body`,`published` from `blog` WHERE user_id=? ';

$stmt=$conn->prepare( $sql );
$stmt->bind_param( 's',$_SESSION['user_id'] );

$res=$stmt->execute();
if( $res ){
    $stmt->store_result();
    $stmt->bind_result($image,$title,$sub_title, $username, $blog_id,$body,$published);

      while( $stmt->fetch() ){
          
       $filepath="../assets/img/blog_images/";

        $title= substr($title,0,30);
        $body= substr($body,0,500);
             
        $date=   date('dS F Y', strtotime($published));
      
$output .=  '
<div class="col-sm-6 col-md-6 col-lg-4">
<div class="blog grid-blog">
<div class="blog-image">
<a href="#">';
$output .=  ' <img style="height:190px; width:330px;" class="img-fluid" src="data:image/png;base64, %s" alt="" />'; base64_encode(file_get_contents($filepath.$image) ) ;     
       
$output .=  ' </a>
</div>
<div class="blog-content">
<h3 class="blog-title"><a href="blog-details.html"> '.$title.' </a></h3>
<p>  <code>  '.$body.'  </code>  </p> <br>
<a href="blog-details.html" class="read-more"><i class="fa fa-long-arrow-right"></i> Read More</a>
<div class="blog-info clearfix">
<div class="post-left">
  <ul>
     <li><a href="#."><i class="fa fa-calendar"></i> <span>'.$date.'</span></a></li>
  </ul>
</div>
<div class="post-right"><a href="#."><i class="fa fa-heart-o"></i>21</a> <a href="#."><i class="fa fa-eye"></i>8</a> <a href="#."><i class="fa fa-comment-o"></i>17</a></div>
</div>
</div>
</div>
</div>';

}

echo $output;

    }else{

        echo 'No any post found';
    }     
?>
有人能指导我如何解决这个问题吗?如果有人能指导我,我将不胜感激。谢谢。

我想您省略了函数。 这应该行得通

sprintf(“”,base64编码(文件获取内容($filepath.$image));

您可以将图像二进制文件放在单独的变量中,以便于使用

$binary=“data:image/png;base64,”.base64_编码(文件获取内容($filepath.$image));

像这样使用它

$output .= '<img style="height:190px; width:330px;" class="img-fluid" src="' . $binary . '" alt="" />';
$output.='';

为什么要把它放在base64 encode上?你可以直接把src标记的路径url放在它的工作文件中,我使用的是这个方法,但是使用
HTML
内容时出现的问题这个问题我想说的和@Jerson一样,并检查浏览器中的inspect元素,看看你得到了什么。复制base64并检查是否base64在联机工具中是正确的。它显示
如果您可以使用图像,请始终尝试仅使用图像而不将其转换为其他内容。现在,每次加载页面时,服务器都需要转换图像如果您仅使用原始图像,则图像会缓存在浏览器中,以便页面加载速度更快