Bhavin Toliya
Bhavin Toliya

Reputation: 31

how to show blob image in html?

I have a image stored in mysql as mediumblob and now I want to show it in html page, so I am doing this with it:

$c = base64_encode($resu[0]->image);
$image = '<img src="data:image/jpeg;base64,'.$c.'" />';
echo $image;

But I am getting only half of original image, so am I missing something here ?

Upvotes: 1

Views: 6770

Answers (3)

user3470953
user3470953

Reputation: 11335

Just an idea, may be you can seperate the logic to display the image. What I mean is that you can create a file like image.php that accepts the id or filename of the image and then display the image. Then you can simply refer the image in your HTML by, for example, doing something like this:

<img src="image.php?imgId=12547"/>

in image.php file something like the following

$imgId=isset(GET['imgId'])?GET['imgId']:0;

$sql = "SELECT * FROM theBlogs WHERE ID = $imgId;";

$result = mysql_query($sql) or die(mysql_error());  
$row = mysql_fetch_array($result);

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

Upvotes: 1

Balaji Rajendran
Balaji Rajendran

Reputation: 367

Display in li tag means use this
<li data-thumb='<?php echo "data:image/jpeg;base64,".base64_encode($img1 ); ?>'> <div class="thumb-image"> <img <?php echo 'src="data:image/jpeg;base64,'.base64_encode( $img1 ).'"';?> data-imagezoom="true" class="img-responsive" alt=""> </div> </li>

Upvotes: 0

Uriziel
Uriziel

Reputation: 177

Just perform a quick test with strlen on $resu[0]->image variable and check blob size in DB and check if they are different sizes for sure.

Upvotes: 0

Related Questions