Chapter 9. Binary Objects and Image Loading
Right now, you’ve got images on a file system, and paths to those images in a database. Then, in your web application, you convert that file system path to a web path, and display the image. This works, and actually works pretty well. In fact, you could run with that solution and likely never have any real issues…and then again, you might have a huge issue that crops up next week.
The real 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. So you’ve created a real connection—sometimes called a tight coupling—between your file system, your PHP, and your database.
So 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 some of your information going into your database, it all goes into your database.
In this approach, you’d actually take the uploaded image and put it in your database, rather than just storing a reference to your image. But to do that, there’s a lot more work to be done: you need not just a new column in your users table, but an entirely new table; you need a new data type; and you need more than just the SELECT and INSERT ...