Page 1 of 1
images in database....
Posted: Tue Jan 27, 2004 12:18 pm
by dull1554
how would one go about storing a image in a sql database.....that is i want the image stored in the database instead of on my server....do you catch my drift....is it possiable if so how would it be done....????!!!!
thanks a mill.......
(i saw someting about it on google and could not find a tutorial to see how its done.....and checked the php man...but with no luck)
Posted: Tue Jan 27, 2004 12:47 pm
by xisle
a blob is used for storing binary data...
http://www.mysql.com/doc/en/BLOB.html
Posted: Tue Jan 27, 2004 12:52 pm
by Gen-ik
You need to create a BLOB (or LONGBLOB) column in your database, read the image file into a $var (using fread() for example) and then chuck it into your database in the usual way.
To read it you will need to load the image string from the database (in the usual way) and then use something like header("Content-Type: image/jpeg"); echo $imageBlob;
It's not too difficult to get sorted but the general rule of thumb is not to store images in a database, just keep the images in a folder and then just add the path name of the image to the database. It doesn't matter if your images are in a database or in a folder they still take up the same amount of server space, and image loading from a database tends to be a lot slower than loading them from a folder.
Posted: Tue Jan 27, 2004 1:58 pm
by dull1554
ahhhh, see i did not know that, thanks for the help....maybe ill just keep them in a folder with a link to the image in the database....thanks a bunch
Posted: Tue Jan 27, 2004 2:37 pm
by pickle
Another method I've heard of (but never tired personally), is using the encode64() function to convert the image to a 64bit encoded string. Then, when you want to display the image, just use decode64() on the string, and dump it to the browser. File extensions will not be preserved, but from what I've heard, the file headers will be, so the browser will display the image properly.