I have some jpg images in MySQL table. How can I display these images?
Could someone please开发者_Go百科 help me by providing sample code?
<?php
$image = $row['myimage'];
header("Content-type: image/gif");
print $image;
exit;
>?
But it seems easier just to store the path...
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
精彩评论