I’ve been a big fan of storing as much information in the database as possible. This includes HTML pages, PHP-executable files, and images.
It’s a simple concept, really. If it can be stored in a file system, it can be stored in a database. They’re essentially the same thing.
Putting image data into a database is not as simple as copy and paste (especially if there are hundreds or thousands of images to migrate). This system is only recommended for small images (icons, sprites, etc) unless you have a powerful server with a large dedicated amount of memory.
An easy way to migrate image data into a database is to create a PHP script that grabs the images’ raw content and parses it into a SQL query, placing the image into a row. Other things you may want to include in the script is the images’ resolutions, byte count, image compression (GIF, JPEG, PNG, etc) and a pseudo-filename. This will make it much easier to organize and access if you’re developing an application on top of this data.
The same can be done for any type of file. All that you need to do is output a Content-type header on your web server. Images, audio, video, anything.
I will be creating a PHP script that does this so check back every so often and you’ll find it in the Scripts page.

No comments