开发者

Structurizing files without db

Basically i have simple form which user uses for files uploading. Files should be stored under /files/ directory with some subdirectories for almost equally开发者_JAVA技巧 splitting files. e.g. /files/sub1/sub2/file1.txt

Also i need to not to store equal files (by filename).

I have own solution. Calculate sha1 from filename. Take first 5 symbols - abcde for example and put file in /files/a/b/c/d/e/ this works well, but gives situation when one folder contains 4k files, 2nd 6k files. Is there any way to make files count be more closer to each other? Max files count can be 10k or 10kk.

Thanks for any help.

P.S. May be i explained something wrong, so once again :) Task is simple - you have only html and php (without any db) and files directory where you should store only uploaded files without any own data. You should develop script that can handle storing uploads to files directory without storing duplicates (by filename) and split uploaded files by subdirectories by files count in each directory (optimal and count files in each directory should be close to each other).


I have no idea why you want it taht way. But if you REALLY have to do it this way, iI would suggest you set a limit how many bytes are stored in each folder. Everytime you have to save the data you open a log with

  1. the current sub
  2. the total number of bytes written to that directory

If necesary you create a new sub diretory(you coulduse th current timestempbecause it wont repeat) and reset the bytecount Then you save the file and increment the byte count by the number of bytes written.

I highly doubt it is worth the work, but I do not really know why you want to distribute the files that way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜