O'Reilly logo

PHP & MySQL: The Missing Manual, 2nd Edition by Brett McLaughlin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required