Reputation: 59323
I have at my disposal PHP, MySQL and a Linux server.
The site I'm creating for a client should have a back-end manageable photo gallery.
I am planning to create it fully in MySQL, meaning I would have a table containing a mediumblob that would contain the binary data of the picture. This would allow me to have everything at one spot, not having to rely on the chance that the client wouldn't accidentally remove an image from the gallery directory without updating the database and so forth.
The alternative, of course, would be to have the images independent of the MySQL database, and only save the image paths.
What I'm posting a question here for is to ask you experts if there are any potholes in this method I'm not seeing. I have never tried this method of creating a gallery before. For instance, is it considered bad practice retrieving large amounts of data from MySQL when file-system storage is possible?
What are your thoughts?
(I will mark correct the reply that erases all doubt about this case from my mind)
Upvotes: 0
Views: 202
Reputation: 3660
Personally, I wouldn't recommend you reinvent that wheel... especially if you want your clients/users to be updating this data. Far better to look to an already existing solution. There are tons of them out there. Probably the most robust is Gallery
As for your actual question, there are lots of reasons not to store binary files in the db. (And only a few that I know about to do so.) Size is a definite consideration. Many hosting providers have a much smaller size limit to your database than filesystem limit. You would be tying them to providers that allow enormous database filesizes. Additionally, apache is VERY good at serving static files to the client. PHP passing those binary files through is going to be WAY slower. Your site's speed would definitely suffer.
Upvotes: 3
Reputation: 23098
I would not store images in the database since you probably want to enable client and/or server side caching for those images. Storing images in the DB will not do any good for this. Store the path of the image in the database and not the file itself.
Upvotes: 3
Reputation: 20475
I wouldn't store images in the database, grows you database way too big. I would make references to the images on the file system. Database reserved for meta data on the images in question.
Also curious why you don't just opt for an open source image gallery to start with like ZenPhoto? And build on that for the customer?
Upvotes: 0