How to display an image stored in the mysql BLOB field on a php page? [duplicate]

2

I have a saved image in my mysql blob encoded in base 64. However, I can not display the image on a simple php page. Actually what I want is for the user to click on a product category, to be returned a search done in php that returns the values of the field and also the images of each product. It follows my php code that is returning a broken image on my page and not the image that is stored in my database. Please, I would like to find where the error is in my code.

    <?php

        require "conexao.php";

                    $sql = "SELECT * FROM produtos WHERE idProduto = 17;";

                    $result = mysqli_query($conexao, $sql) or die(mysql_error());  
                    $row = mysqli_fetch_array($result);

                    echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['imagemProduto1'] ) . '" />';

        mysqli_close($conexao);
    ?>
    
asked by anonymous 27.07.2016 / 04:08

1 answer

3

I found the error. did not need to decode back. The image is already coming ready to be displayed.

In this way, the line that looked like this:

 echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['imagemProduto1'] ) . '" />';

looks like this:

 echo '<img src="data:image/jpeg;base64,' . $row['imagemProduto1'] . '" />';

Solved!

    
27.07.2016 / 04:31