Open BLOB in php

1

I have a field of type BLOB to save images in my mysql, the image comes from an android APP via POST, the way the BLOB string arrives I saved in the bank.
When I try to show the contents of this BLOB in a page, everything goes blank. PHP code that I use to show the image:

<?php   
    //header('Content-Type: image/jpeg');
    include('conexao.php');
    include('funcoes.php');
    $sqlImagem = "SELECT foto from combustivel_abastece;";
    $consultaImagem = mysql_query($sqlImagem, $connection) or die (print "Erro TABELA consulta imagem <br>".mysql_error());
    if ((mysql_num_rows($consultaImagem) > 0)) {
        while($row = mysql_fetch_assoc($consultaImagem)) {
            echo '<img src="data:image/bmp;base64,'.base64_encode( $row['foto'] ) .'" /> <br>';
        }   
    }               

?>

Detail: the same string that I send to mysql, if I try to show in Android APP, it works

    
asked by anonymous 11.09.2017 / 18:52

2 answers

1

Try this:

<?php   
    //header('Content-Type: image/jpeg');
    include('conexao.php');
    include('funcoes.php');
    $sqlImagem = "SELECT foto from combustivel_abastece;";
    $consultaImagem = mysql_query($sqlImagem, $connection) or die (print "Erro TABELA consulta imagem <br>".mysql_error());
    if ((mysql_num_rows($consultaImagem) > 0)) {
        while($row = mysql_fetch_assoc($consultaImagem)) {
            echo '<img src="data:image/bmp; base64(data:image/bmp;base64,'.base64_encode( $row['foto'] ) .'" /> <br>';
        }   
    }               

?>
    
11.09.2017 / 19:04
1

I solved the problem. The error was not only in php. I need to convert the string to base64 before sending to mysql That way my php code looks like this

echo '<img style="width:100;height:100" src="data:image/png;base64, '. $row['foto']  .'" /> <br>';
    
11.09.2017 / 19:24