Welcome to WebmasterWorld Guest from 23.20.10.127

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

how to convert blob to image in php

     
5:30 am on Jun 6, 2006 (gmt 0)

New User

10+ Year Member

joined:June 6, 2006
posts:3
votes: 0


I am using Smarty as templates in my site...I have images stored as blob in db i can get this blob to image using header(content-type: image/jpg) but i wann to assign this image to smarty variable How to do that? please help me
12:08 pm on June 6, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


Welcomme to WebmasterWorld, bhavnagadhiya.

if ($row = mysql_fetch_array(mysql_query('SELECT image FROM imageMySQL'))) { 
$image = $row['image'];
}

You just assign it as you would any other variable.
12:16 pm on June 6, 2006 (gmt 0)

New User

10+ Year Member

joined:June 6, 2006
posts:3
votes: 0


Thank you...

its printing the binary data itself in page

12:18 pm on June 6, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


Yes, and it will unless you send the proper mime type out prior to it's display.
header("Content-type: image/jpg"); 
print $row['image'];
12:25 pm on June 6, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


Also, there is a thread in our PHP Forum Library [webmasterworld.com] that discusses How to convert image blob files back to image [webmasterworld.com] which you may find useful.
12:28 pm on June 6, 2006 (gmt 0)

New User

10+ Year Member

joined:June 6, 2006
posts:3
votes: 0


its same thing coopster

see i am displaying this templates variable only in to html page i cant use header in html page u know that...

i cant use headet and print function in my tpl(html/templates)..

3:27 pm on June 6, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Nov 3, 2003
posts:324
votes: 0


You should consider changing this setup. Storing images as blobs in dbs is:

1. space inefficient;
2. resource inefficient (time to http display an image v. db query plus php process plus http)
3. and difficult to maintain.

A faster/cleaner setup is to setup a file server, save the image there and just save the image location, name, size and lastupdatedatetime to the db.

7:13 pm on June 6, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


bhavnagadhiya, you are correct, but if you study the discussion given in my last post you will see how you can accomplish what you desire. You have a php script that accepts an image identifier and retrieves it from the database table. Then, at the end of that script you print out the appropriate header as well as the binary image data. You refer to this script in your <img> element in the HTML. Read the example again carefully and you will see how it is done.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members