2

I know this question was asked in various ways here, but none of the answer is conclusive.

I have a system which among other things updates a website gallery. I can both "upload" the file to the website (and save a copy at the system - needed) or just save it in the DB and save the space (and another upload). If I go with the files I would need to "notify" the webpage of every change (picture delete, add or change) instead of just making the change in the DB.

So:

  1. If we are talking about a standard website with a picture gallery, is it best to save the pictures as pictures or in the DB?
  2. If the webpage is very visited or very large, does it makes any difference?

Is the difference that significant? Or just go with the convenient way?

Although I presented my case I would like also to have a "more in general" answer, what is the "good" approach when talking about saving files.

Thanks in advance for clarifying it,

Michel.

Phoenix
  • 1,256
  • 2
  • 17
  • 25
  • possible duplicate of [PHP to store images in MySQL or not?](http://stackoverflow.com/questions/527801/php-to-store-images-in-mysql-or-not) - not really PHP specific, despite its name. – eggyal May 14 '12 at 09:18
  • Related (duplicate?): [Saving images in database mysql](http://stackoverflow.com/questions/2753193/saving-images-in-database-mysql). – mkjeldsen May 14 '12 at 09:21
  • Both not the same. The issue here is that there is no easy way to control the pictures change. If some picture is uploaded the system needs to AJAX the website which makes `get_file_contents` & saves the picture. If the picture is changes i need to delete, then save the new one and etc. Im both of the answers I read there was no such concern. – Phoenix May 14 '12 at 09:27

2 Answers2

0

Only put structured data in a DB. Images are files and should be kept on a files system. The performance of the DB will degrade more and more as the number of pictures / users grows. Instead create an image object which you can use to track the image location and meta data.

codeghost
  • 1,014
  • 7
  • 14
0

I have had the same problem with you in a previous project of mine.

I decided to go with only storing the path of the image in my database (which is just a string) and save the image in the file system, not in the DB.

This is the best practice in many ways. It keeps your DB small, getting a large amount of rows is faster and DB back ups are significantly smaller.

Just put the images in a file and save the path in the DB so you can retrieve it later.

hermann
  • 6,237
  • 11
  • 46
  • 66