Chapter 10. Binary Objects and Image Loading
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 some of your information going into your database, it all 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 your users table, but an entirely new table; you need a new data ...
Get PHP & MySQL: The Missing Manual, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.