RE: [PHP] insert & select image in mySQL

From: Date: Mon, 21 Jan 2002 05:40:02 +0000
Subject: RE: [PHP] insert & select image in mySQL
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-81329@lists.php.net to get a copy of this message
Try this code. It assumes you are already connected to the database. Usually, I put that script in something like database.inc and just do an include. <?php mysql_connect ("mysql_server", "username", "password"); mysql_select_db("database_name"); $sql = mysql_query("SELECT image, type FROM table_name WHERE pid='$id'"); $file = mysql_fetch_row($sql); header("Content-type: $file[1]"); echo $file[0]; ?> pid is the picture id. I'll assume you'll have an index or something in your database setup. Now, type is based on the extension of the file really. If filename.gif is uploaded, it is assumed that the header type is image/gif. How do you use this? Save this little script as a seperate file. It is now the image file. Observe: <img src="foobar.php?id=24"> Now, assuming that the file you saved it as is foobar.php, the script will fetch the binary data of whatever is at pid 24. > -----Original Message----- > From: Rio Uniwaly [mailto:rio1978@yahoo.com] > Sent: January 21, 2002 12:01 AM > To: php-general@lists.php.net > Subject: [PHP] insert & select image in mySQL > > > aloo, sorry if this question was already asked before.. :-( > i'm going to insert an image from html form to the mysql > when i'm going to insert it's run good, but when i'm going to > select it from mysql, > i've got nothing.. > could someone have an advice?? > thank you... > > Rio Uniwaly > www.prio.mysite.de > email:prio@mysite.de > >

« previous php.general (#81329) next »