Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't retrieve Image from my database

I have a database containing movies Name, their description and their cover picture. The cover picture field type is as blob and the problem is that I can't retrieve it from the database. I want to display the movie name along their cover picture beside them... How to do it.. Here is my code..

<?php

include ("php/connection.php");
$ID = $_GET['id'];
$listmovies = "SELECT * FROM movies where Genres LIKE '%$ID%'";
$result = mysql_query($listmovies);
while ( $row = mysql_fetch_assoc($result) ) {
    ?>
<table border="1" width="100%">
    <tr>
        <td rowspan="2" width="90" height="120">
<?php

    // set the header for the image
    header("Content-type: image/jpeg");
    echo $row['Image'];

    ?> </td>
        <td width="200" height="10">
<?php

    echo $row['Title'];
    ?></td>
    </tr>
    <tr>
        <td width="200" height="110"><a
            href="php/moredetails.php?id=<?php echo $row['ID']; ?>">More Detail</a></td>
    </tr>
<?php } ?> </table>

I just want to display The Imgaes beside the title of the movie?

like image 785
Shubhum Avatar asked Nov 03 '22 13:11

Shubhum


1 Answers

Yes it won't display because any output above header would always generate error ... you need to have a different page to output your image or include it has base64 image

Remove

header("Content-type: image/jpeg");
echo $row['Image'];

And add this :

printf("<img src=\"data:image/jpeg;base64,%s\" />",base64_encode($row['Image']));  
                               ^--- Note this is only for jpeg images
like image 162
Baba Avatar answered Nov 14 '22 19:11

Baba