S
S
semki0962016-03-10 10:21:17
CodeIgniter
semki096, 2016-03-10 10:21:17

How to organize the storage of avatars?

I store avatars in the upload/avatars folder. I want to organize storage like this: upload/avatars/first 500 avatars, upload/avatars/second 500 avatars, etc. How to do this, or perhaps there is a better option? Yes, there is a question along the way, which must somehow be calculated.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Silm, 2016-03-10
@semki096

The name for the file is hashed into a random hexadecimal string. The file is saved to a directory whose name is the first n characters of the file name. For example, if n = 2, and the file name is 0aac4e6a54c170b06e2bd3848d2b735e.jpg, then the file will be saved to this path upload/avatars/0a/0aac4e6a54c170b06e2bd3848d2b735e.jpg
With two characters, the files will be distributed evenly across 256 directories. You can use a different number of characters or nested directories (0a/ac/4e/6a) depending on how many files you have.
Thus, knowing only the name of the file and the algorithm by which the split occurs, we can build the full path to the file.
Or. You can check how many files are in the directory every time you save a file. If more than the limit, then create a new directory, save to it and write to the database the full path to the file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question