June 16th, 2000, 02:28 PM
I've noticed a number of questions on the board about storing images in databases. My question is this (hopefully it's a simple one)
Can the actual jpg/gif image be stored as data in the database... or is it just a path to where the image is stored?
If it can be stored as actual data.... how?
June 19th, 2000, 04:31 AM
From what I know about mySQL it is possible to store an image in a database under the BLOB (Binary Large OBject) datetype. However, the maximum size of your picture is limited to 65535 bytes. In order to get your picture into your database I presume you'd do something like this:
<form action=POST enctype=multipart/form-data method=add.php3>
<input type=file name=file>
// Assume already connected to database
insert into table values (
That's how to get it in, assuming you have a table called test with one column that is a BLOB datatype: you'll have to use PHP or similar to view the image on a web page, which means that the image tag is going to be something like this:
which is a bit wierd!
You also might run into problems here if your web host has set a maximum amount of table space that you can use. Whilst 10MB might seem ample for a database containing text, when you start to add pictures it will be used up very quickly! This is another reason why people use the image-copying way of doing it. Personally, when I'm adding records to a database, I'll use PHP to generate a random number, then that random number becomes the image name as well so there's no possibility of the file overwriting another on the server.
[This message has been edited by alexgreg (edited June 19, 2000).]