Open BLOB in php

Asked

Viewed 471 times

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 string BLOB arrives I saved in the bank.
When I try to show the contents of this BLOB on a page, everything is blank. PHP code 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 the Android APP, it works

2 answers

1

Try this way:

<?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>';
        }   
    }               

?>

1

I solved the problem.
The error was not only in php. I needed to convert the string to Base64 before sending it to mysql That way my php code got the following way

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.