如何让我的数据库图像显示在 table 中?

How can I make my DB images be displayed in the table?

我现在的table是这样的:http://imgur.com/ZMb6Ade

图像直接进入数据库,因此服务器中没有任何文件可以存储图像。

Select3.php:

<?php  
 $db_host        = 'localhost';
 $db_user        = 'root';
 $db_pass        = '';
 $db_database    = 'crc'; 
 $output = ''; 
    $db = new PDO('mysql:host='.$db_host.';dbname='.$db_database, $db_user, $db_pass);
    $result = $db->prepare("SELECT * FROM pulseiras ORDER BY ref ASC ");
    $result->execute();     
$output .= '  
  <div class="table-responsive">  
       <table class="table table-bordered">  
            <tr>  
                 <th width="10%">REF</th> 
                 <th width="25%">Nome</th> 
                 <th width="25%">Preço</th>  
                 <th width="25%">Imagem</th> 
            </tr>';  
 if (count($result) > 0)   
{  
 for($i=0; $row = $result->fetch(); $i++){ 
       $output .= '  
            <tr>  
                 <td>'.$row["ref"].'</td>  
                  <td class="nome" data-ref1="'.$row["ref"].'" contenteditable>'.$row["nome"].'</td>  
                  <td class="preco" data-ref2="'.$row["ref"].'" contenteditable>'.$row["preco"].'</td> 
                  <td class="imagem" data-ref3="'.$row["ref"].'" contenteditable><img src="data:image/jpeg;base64,'.base64_encode( $row['imagem'] ).'"/></td> 
                 <td><button type="button" name="delete_btn" data-ref5="'.$row["ref"].'" class="btn btn-xs btn-danger btn_delete">X</button></td>  
            </tr>  
       ';  
  }  
  $output .= '  
       <tr>  
            <td></td>  
            <td id="nome" contenteditable></td>  
            <td id="preco" contenteditable></td>  
            <td id="imagem" contenteditable></td>    
       </tr>  
  ';  
}  
else  
{  
     $output .= '<tr>  
                      <td colspan="4">Data not Found</td>  
                 </tr>';  
}  
$output .= '</table>  
     </div>';  
echo $output;  
?>  

图像类型为 BLOB。感谢任何帮助。

我最后一次这样做是在 C# 中,所以我没有任何 PHP,但这里是伪代码的基本思想:

一个单独的页面服务器 blob,将其称为 getblob.php,使用任何参数,例如 getblob.php?blogname=myblob.jpg:

select blob from blobtable where name='myblob.jpg'
execute, fetch, etc...

set mime type = image/jpeg
do some buffering here if the blobs are big
echo $blob

在你的html中:

<img src='getblob.php?blobname=myblob.jpg'/>
<img src='getblob.php?blobname=myotherblob.png'/>
etc....

这允许浏览器单独缓存图像,允许您在 blob 很大时进行缓冲,速度更快,因为没有编码,不会给您留下大量 html 嵌入的页面base64 字符串,是可移植的,因为 blob 可以很容易地链接到您想要的任何其他页面,允许插件仅执行 blob url 如果它是 pdf 等...

编辑以添加来自某个站点的 php 示例:here