Reputation: 1409
I have some jpg images in MySQL table. How can I display these images?
Could someone please help me by providing sample code?
Upvotes: 1
Views: 1179
Reputation: 14318
The concept is somewhat similar to the below code where img1.jpg
is an image file
$handle = fopen('img1.jpg', 'r');
header("Content-type: image/gif");//make sure that you dont have output before it
echo fread($handle, filesize('img1.jpg'));
And try for next experiment
$handle = fopen('img1.jpg', 'r');
echo fread($handle, filesize('img1.jpg'));
//If you are storing the output of this in
//your db then this should work
//however it is best recommended to store
//path which makes you jog a lot easir
//if you get the same error then you have error in
//storing your file
Upvotes: 0
Reputation: 18139
<?php
$image = $row['myimage'];
header("Content-type: image/gif");
print $image;
exit;
>?
But it seems easier just to store the path...
Upvotes: 2