0

I have a database which contain blob images. I want to display them in a webpage. I'm using the following php code to get the image. But it didn't work properly.

<?php
        while($row=mysql_fetch_array($results))
        {?>
            <tr>
               <td><img src="<?php echo $row["image"]?>" height="200" width="250"></td>
            </tr>
            <?php
        }?>

With this code I'm getting a webpage like this.

enter image description here

Where I have to do the correction to my code.

KMA
  • 211
  • 3
  • 17
  • you need to change src to point to a scrip that will exact the blob and set the correct file headers –  Aug 04 '15 at 03:18
  • 1
    side note: it is generally recommended not to store files in the db, but in the file system, just store the file-name\location in the db. –  Aug 04 '15 at 03:21
  • same issue as this [stackoverflow.com/questions/13225726/i-need-my-php-page-to-show-my-blob-image-from-mysql-database](http://stackoverflow.com/questions/13225726/i-need-my-php-page-to-show-my-blob-image-from-mysql-database) – ar em Aug 04 '15 at 03:23
  • The arguments for and against have been rehearsed ad nauseam. Certainly the alternative model is vastly more popular but not necessarily more appropriate. Either way, this question has been answered before – Strawberry Aug 04 '15 at 06:29

1 Answers1

2

try to convert it to base64:

<img src="data:image/jpeg;base64,<?php echo base64_encode($row['image']); ?>" height="200" width="250">

Note that you should also store the image type in your DB, so you can dynamically change "data:image/jpeg".

VMcreator
  • 833
  • 8
  • 17