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:[EMAIL PROTECTED]]
> Sent: January 21, 2002 12:01 AM
> To: [EMAIL PROTECTED]
> 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:[EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to