Re: insert & select image in mySQL

From: Date: Fri, 25 Jan 2002 00:11:32 +0000
Subject: Re: insert & select image in mySQL
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-82014@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. > It doesn't run for me. I always got an eternal red cross in place of the picture I'm looking for...Any idea ? ---------------------------------- Stéphane Pinel 39, Rue du Docteur Heulin 75017 Paris (FRANCE) 33 1 53 11 05 77 33 6 08 94 63 16 spinel@noos.fr ----------------------------------

« previous php.general (#82014) next »