homepage Welcome to WebmasterWorld Guest from 54.237.151.188
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
how to convert blob to image in php
bhavnagadhiya

5+ Year Member



 
Msg#: 13127 posted 5:30 am on Jun 6, 2006 (gmt 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

 

coopster

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



 
Msg#: 13127 posted 12:08 pm on Jun 6, 2006 (gmt 0)

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.

bhavnagadhiya

5+ Year Member



 
Msg#: 13127 posted 12:16 pm on Jun 6, 2006 (gmt 0)

Thank you...

its printing the binary data itself in page

coopster

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



 
Msg#: 13127 posted 12:18 pm on Jun 6, 2006 (gmt 0)

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'];

coopster

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



 
Msg#: 13127 posted 12:25 pm on Jun 6, 2006 (gmt 0)

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.

bhavnagadhiya

5+ Year Member



 
Msg#: 13127 posted 12:28 pm on Jun 6, 2006 (gmt 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)..

stajer

10+ Year Member



 
Msg#: 13127 posted 3:27 pm on Jun 6, 2006 (gmt 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.

coopster

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



 
Msg#: 13127 posted 7:13 pm on Jun 6, 2006 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved