At this point. you have images on a file system, and the paths to those images .stored in a database. In your PHP scripts, you convert that file system path to a web path, and then display the image. This works, and it works pretty well. In fact. you could run with that solution and likely never have any issues …but. then again, you might have a huge issue that crops up next week.
The downside of this approach is that you don’t have a self-contained solution Images are on the file system, paths are in the database, and then you need some PHP to convert from the location of the image on your server to a path that users’ browsers can interpret correctly. To put it all together, you’ve created a real connection- sometimes called a tight coupling -between your file system, your PHP, and your database.
Taking all this into consideration, how do you make things more self-contained? You’d have to take these pieces of information and put them all in one place. Obviously, you’re committed to a database, so that becomes the logical place to consolidate your information. Instead of your information going into your database, it goes into your database.
In this approach, you take a user’s uploaded image and put it in your database rather than just storing a reference to your image. Unfortunately, to do that, there’s a lot more work to be done: you need not just a new column in yours table, but an entirely new table; you need a new data type; and you need more than just the SELECT and INSERT queries you’ve been using so far. If you need this type of solution, this chapter will show you how to do it.