I cant find how to output an image that are storing in a mysql database to a html page..
Can some one help me please
I can insert a image into an mysql just fine, but getting it out,, i cant understand..
Its like this, my members on my site should upload an picture on what ever they want, and it should be posted on the userinformation.
//Thanx
Output image from a mysql to a html page
Moderator: General Moderators
-
fractalvibes
- Forum Contributor
- Posts: 335
- Joined: Thu Sep 26, 2002 6:14 pm
- Location: Waco, Texas
Write a script that is responsible for streaming the image to the browser. It needs to:
1.) read the database for that image
2.) determine the content-type (determine and store in db when you
load the image)
3.) Add a http header setting the content type appropriately
4.) echo the image out to the browser
Other pages will call this script via a link tag as in:
<a href=DisplayImage.php?ID=437>Cat Photo</a>
Check the PHP manual for references to AddHeader and also
for the various properties available to you when you upload a file.
Be sure and also store the content type - image/gif, image/pjpeg, even application/pdf! That way you have a universal(almost) media server application.
fv
1.) read the database for that image
2.) determine the content-type (determine and store in db when you
load the image)
3.) Add a http header setting the content type appropriately
4.) echo the image out to the browser
Other pages will call this script via a link tag as in:
<a href=DisplayImage.php?ID=437>Cat Photo</a>
Check the PHP manual for references to AddHeader and also
for the various properties available to you when you upload a file.
Be sure and also store the content type - image/gif, image/pjpeg, even application/pdf! That way you have a universal(almost) media server application.
fv
-
Cruzado_Mainfrm
- Forum Contributor
- Posts: 346
- Joined: Sun Jun 15, 2003 11:22 pm
- Location: Miami, FL
the script to read the image is like this:
hope this helps
call it like this: image.php?id=1
be sure to edit this to fit your needs of course
Code: Select all
$id = $_GET['id'];
@mysql_connect("localhost","root");
@mysql_select_db("test");
$query = "SELECT binarydata FROM images WHERE id = '$id'";
$result = @MYSQL_QUERY($query);
$data = @mysql_result($result,0,"binarydata");
Header( "Content-type: image/jpeg"); //image/png also you can even say application/x-shockwave-flash if you have the binary data of a .swf flash file
echo $data;call it like this: image.php?id=1
be sure to edit this to fit your needs of course
Hi,
Cruzado_Mainfrm i tried your code and i dont get it to work wright.
My mysql table look like this
TABLE NAME image
image_id int(10) unsigned NOT NULL auto_increment,
image_type varchar(50) NOT NULL default '',
image longblob NOT NULL,
image_size bigint(20) NOT NULL default '0',
image_name varchar(255) NOT NULL default '',
image_date datetime NOT NULL default '0000-00-00 00:00:00',
UNIQUE KEY image_id (image_id)
I dont get it how i should print the image, your code looks to work, but i get a "red cros" (cant find the image) like this
http://www.theemperorsfinest.com/test/image.php
Cruzado_Mainfrm i tried your code and i dont get it to work wright.
My mysql table look like this
TABLE NAME image
image_id int(10) unsigned NOT NULL auto_increment,
image_type varchar(50) NOT NULL default '',
image longblob NOT NULL,
image_size bigint(20) NOT NULL default '0',
image_name varchar(255) NOT NULL default '',
image_date datetime NOT NULL default '0000-00-00 00:00:00',
UNIQUE KEY image_id (image_id)
I dont get it how i should print the image, your code looks to work, but i get a "red cros" (cant find the image) like this
http://www.theemperorsfinest.com/test/image.php