It seems that the latest and greatest use for databases is storing large amounts of binary data, known as BLOB's. These BLOB's can store just about any type of data imaginable, including MS Word documents, GIF/JPEG images, PDF files, MP3's, etc. In this article Mitchell shows us how to create a binary file repository using PHP and MySQL that can store and retrieve several different file types.
Blobbing Data With PHP and MySQL - Adding blobs to the database (Page 3 of 7 )
Now that we've got our table structure sorted out, let's use a simple PHP script to capture files from a users computer and store them in our database. Create a new PHP script named getfiles.php and save it into a directory that your web server can process. Enter the following code into getfiles.php:
<input type="submit" value="Upload this file" name="cmdSubmit"></font></td>
In the page above, we've created a HTML form that allows us to send files to the server. It allows the user to choose a file to upload, and to also enter a description for that file. The only difference between the form above and any other HTML form, is that the enctype attribute of our form is set to "multipart/form-data":
This tells the browser that we may be sending files from the client's machine to the server, so it should be ready to prepare the headers and stream the files to the server, amongst other things. Our getfile.php page looks like this:
Our form will post its results to grabfile.php, which will be responsible for adding the file to the database as a BLOB. Let's create that file now.