List:General Discussion« Previous MessageNext Message »
From:kalle volkov Date:March 14 1999 9:55am
Subject:Re: Displaying image from database
View as plain text  
hi!

if u use PHP3 and MySQL then the PHP script should look smthng like
this:
---
image.php3
---
<?
MYSQL_CONNECT("my.host.somewhere","myuser","myspassword") OR DIE("server
is not reachable");
@MYSQL_SELECT_DB("MyDatabase") OR DIE("database is unavailable");
$question = MYSQL_QUERY("SELECT image FROM table WHERE ID = '$myID'");  
$image = MYSQL_RESULT($question,0,"image");
Header(  "Content-type:  image/gif");  
echo $image; 
flush(); 
?>
---

and in html/php3 script that calls the script add 
---
showimage.php3
---
<IMG SRC="image.php3?ID=foo">
---

also, in showimage it's nice to determine size of image and add WIDTH
and HEIGHT tags...

regs,
cal6

---

Robert Hazeltine wrote:
> 
> Hi
> I am working on a project whereby all the relevant data is stored in the
> Mysql database and then when required the data is compiled into
> a web page.
> 
> I have all the text data working properly, but cannot figure out how
> to display the image BLOBS I have created at the same time, or
> being able to format them within the appropriate HTML tags.
> 
> I was hoping I could do something similar to (pseudo-code):
> 
> # get the image from the database
> $image = "select image from table where id = foo";
> 
> # display the image in HTML
> 
> <IMG SRC = "$image">
> 
> I tried many different ways of getting to this, but none of them
> work.  I found an example in a news archive somewhere that lets
> me display the BLOB direct from the database, but it requires that
> I pass a lot of the information about the file (content/type &c)
> myself and it does not let me do any proper formatting on the images
> layout and nor can I display text in the browser at the same time.
> 
> Given that I have my image BLOB properly accessible in the database,
> and I can already pop out any arbitrary text as I wish, what do I
> do next for images?
> 
> Thanks
> 
> Rob...
> Robert Hazeltine                      Member of UWSN Web Management Group
> Project Officer (Web Development)     Phone:  +61 (2) 4736 0218
> Central Administration                Email:  r.hazeltine@stripped
> University of Western Sydney, Nepean  http://www.nepean.uws.edu.au/
> 
> ---------------------------------------------------------------------
> To request this thread, e-mail mysql-thread197@stripped
> 
> To unsubscribe, e-mail the address in the List-Unsubscribe header.
> For additional commands, e-mail: mysql-help@stripped
Thread
Displaying image from databaseRobert Hazeltine14 Mar
  • Re: Displaying image from databasekalle volkov14 Mar
    • Re: Displaying image from databaseRobert Hazeltine14 Mar
      • Re: Displaying image from databaseThimble Smith15 Mar
    • Re: Displaying image from databaseOliver Artelt15 Mar
  • Re: Displaying image from databaseSasha Pachev15 Mar
Re: Displaying image from databaseChris17 Mar
  • Re: Displaying image from databaseTommi Rintala17 Mar