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.

4
  • you need to change src to point to a scrip that will exact the blob and set the correct file headers Commented Aug 4, 2015 at 3: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. Commented Aug 4, 2015 at 3:21
  • same issue as this stackoverflow.com/questions/13225726/i-need-my-php-page-to-show-my-blob-image-from-mysql-database Commented Aug 4, 2015 at 3: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 Commented Aug 4, 2015 at 6:29

1 Answer 1

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".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.