What is the best way to store web application images in a file system

What is the best practice for storing a large number of files referenced in a database in a file system?

We are currently moving from a system that stores about 14,000 files (about 6 GB of images and documents) into a MySQL database. It quickly becomes unmanageable.

Currently, we plan to save files using the primary key of our database in the file system. I am worried about possible performance issues related to the fact that many files are in the same folder. In addition, these files will be inserted by several different applications on the same server.

In particular, I would like to know:

  • Is this a good solution considering these parameters?
  • Will it leave room for further scaling in the future?
  • Are there any problems storing many files in one place?
  • Is there a better way to name / distribute files?
+3
source share
2 answers

Hash the contents with MD5, then add the suffix (PK is enough for this) to get the file with the new file name. Create 16 folders matching the first hash character. Create 16 folders under each of them for the second character. Save the image in the appropriate path based on the first two hexadecimal characters of the hash, then add the hash to the corresponding record in the database.

+1
source

          /* */ $ dir = date ('Y'). '/'. date ('m'). '/'. date ('d');

+2

Source: https://habr.com/ru/post/1770843/


All Articles