Re: How can i put the image file to the db ? (mssql)
From: Ekkehard Morgenstern (ekkehard.morgenstern_at_onlinehome.de)
Date: 11/13/03
- Next message: Jedi121: "Re: How can i put the image file to the db ? (mssql)"
- Previous message: lawrence: "what do I set my allowed_include path to?"
- In reply to: Alper Adatoz: "How can i put the image file to the db ? (mssql)"
- Next in thread: Jedi121: "Re: How can i put the image file to the db ? (mssql)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 13 Nov 2003 23:45:02 +0100
Hi Alper Adatoz,
"Alper Adatoz" <allper@myway.com> schrieb im Newsbeitrag
news:eae08b72.0311110522.62b12fd3@posting.google.com...
> i just want to put jpeg file to the image field at the mssql db.
I've done this only with MySQL before, but I figure it could be similar with
MSSQL.
1. You can create a BLOB field of the appropriate size in the database
table.
2. Then, you can load the image file that has been uploaded by the user
(like, with file_get_contents() ).
3. Then, you encode the binary data to base64 format using base64_encode().
4. Then, you can simply use it in an INSERT or UPDATE SQL command:
$bindata = file_get_contents( $filename );
$b64data = base64_encode( $bindata );
$result = mysql_query( "INSERT INTO MYTBL ... SET IMAGE='$b64data'",
$dblink );
To retrieve the image stored in the database, simply read the row, access
the field, base64_decode() it and output it to the user.
For output to the user, you can use a specific PHP script that reads the
image from the database, sets the HTTP headers and then outputs the binary
data.
See RFC 2616 (HTTP 1.1 specification), available from
http://www.rfc-editor.org, for information about the HTTP protocol.
This method has one disadvantage, that if the base64-encoded image data
would exceed the SQL INSERT/UPDATE command length limit. I haven't tried yet
if databases like MySQL can use arbitary-sized SQL queries.
I hope that helps.
Regards,
Ekkehard Morgenstern.
- Next message: Jedi121: "Re: How can i put the image file to the db ? (mssql)"
- Previous message: lawrence: "what do I set my allowed_include path to?"
- In reply to: Alper Adatoz: "How can i put the image file to the db ? (mssql)"
- Next in thread: Jedi121: "Re: How can i put the image file to the db ? (mssql)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|