A
A
atis //2015-12-07 13:12:19
PHP
atis //, 2015-12-07 13:12:19

Where is the best place to store directory information?

Such a thing.
A lot of files are constantly uploaded to the server, and therefore it becomes necessary to group files into folders because 10 thousand files in 1 directory is bad.
A script was written to automatically create directories / subdirectories (there can be a lot of nesting levels!)
And then the problem arose, how to store data about which directory to load files for the current path?
For example:
/files/dir1/
/files/dir2/dir1/
/files/dirName/dir43/
And so on.
Keeping everything in the database is the best and easiest way but I would like to hear your implementation :)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
Cat Anton, 2015-12-07
@atis2345

What directory names to make for a large project?

E
Evgeny Svirsky, 2015-12-07
@e_svirsky

Do you store data about files in the database? why not store the full path to the file with the directory in the same place?
on the other hand, depending on where you use it. If the UI has an implementation of reading the directory structure, then the database does not need to store anything either..

R
Rsa97, 2015-12-07
@Rsa97

1. Create a two-three-level directory structure with names 00-FF at each level. Two levels give 65536 lower-level directories, three - 16777216 directories. You can not create all directories at once, but generate them as needed.
2. To save a file, read it as md5, and take the first pairs of characters as directory names. Let's say if md5 = '1afa148eb41f2e7103f21410bf48346c' then the path would be '1a/fa/14/'. Thus, the files will be scattered in folders.
3. Generate uinqid, save the file in the previously obtained directory under this uinqid on the path you received.
4. Write the full path and original filename to the database.

6
65536, 2015-12-07
@65536

{00-ff}/{00-ff}/{00-ff}/{00-ff}/{00000000-ffffffff}.{ext}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question