没有数据库的结构化文件

发布于 2024-10-07 14:09:17 字数 470 浏览 0 评论 0原文

基本上我有用户用于上传文件的简单表单。文件应存储在 /files/ 目录下,并带有一些子目录,以便几乎均等地分割文件。例如 /files/sub1/sub2/file1.txt

另外,我需要不存储相同的文件(按文件名)。

我有自己的解决方案。根据文件名计算 sha1。以前 5 个符号 - 例如 abcde 并将文件放在 /files/a/b/c/d/e/ 中,效果很好,但会出现一个文件夹包含 4k 文件、第二个 6k 文件的情况。有什么办法可以让文件计数更加接近吗?最大文件数可以是 10k 或 10kk。

感谢您的任何帮助。

PS 可能我解释了一些错误,所以再一次:) 任务很简单 - 你只有 html 和 php (没有任何数据库)和文件目录,你应该只存储上传的文件,没有任何自己的数据。您应该开发可以处理将上传存储到文件目录而不存储重复项(按文件名)的脚本,并按每个目录中的文件计数按子目录拆分上传的文件(每个目录中的最佳文件和计数文件应彼此接近)。

Basically i have simple form which user uses for files uploading. Files should be stored under /files/ directory with some subdirectories for almost equally 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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2024-10-14 14:09:17

我不知道你为什么要这样。但如果您确实必须这样做,我建议您设置每个文件夹中存储的字节数限制。每次您必须保存数据时,请使用

  1. 当前
  2. 子目录打开一个日志,写入该目录的总字节数

如果有必要,您创建一个新的子目录(您可以使用当前时间,因为它不会重复)并重置字节数
然后保存文件并按写入的字节数增加字节计数。

我非常怀疑这项工作是否值得,但我真的不知道为什么你想以这种方式分发文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文