如何通过php从mysql数据库中获取图像

时间:2016-03-29 22:46:16

标签: php mysql

我可以在数据库中插入我的图像,但我找不到一种方法来获取它。图像是通过网站插入的。 我的PHP代码:

require_once('something.php');

    $codservico=$_GET['id'];

    $consulta="select * from xxxxx where xxxxx=".$something;
    $resultado=mysql_query($consulta);
    $nregistos=mysql_num_rows($resultado);
if($nregistos>0)
{
    for ($i=0; $i<$nregistos; $i++){
        $registo=mysql_fetch_array($resultado);
        echo '<tr class="show">';
        echo '<td class="show"><img src="data:image;base64,'.$registo['image'].'"></td>';
        echo '</tr>';
    }
}
else
{
    echo "<td colspan='8' align='middle'>Nenhum registo encontrado</td>";
}

我得到这样的东西: http://costumerbook.netai.net/Capturar.PNG

1 个答案:

答案 0 :(得分:0)

您需要指定Content-Type(图片格式) - data:image/png;base64

echo '<td class="show"><img src="data:image/png;base64,'.$registo['image'].'"></td>';