为用户制作文件管理器的最佳实践

发布于 2024-09-17 07:28:57 字数 206 浏览 2 评论 0原文

我将为用户制作一个文件、资源管理器。我的网站提供帮助用户创建博客、网站并允许用户上传资源的服务。我将创建一个如下所示的文件夹结构。有什么建议吗?

usercontents
--user1
----folder1
----folder2
--user2
--user3
----my images

我应该使用数据库来索引这些文件吗?

I'm going to make a files, resources manager for user. My website provide a service help user create blog, website and allow user upload their resources. I'm will create a folder structure like below. Any suggestion?

usercontents
--user1
----folder1
----folder2
--user2
--user3
----my images

Should I use database to index those files?

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

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

发布评论

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

评论(2

时光无声 2024-09-24 07:28:57

如果我要做这样的事情,首先我会执行以下操作:

  • 将文件类型限制为我指定的几种(图像、mp3、mp4,也许是 swf);
  • 规范用户名或将其限制为字母数字,这样我就不会出现用户名文件夹冲突;
  • 规范化文件名,以便 my Awesome mp3 文件(此处有一些评论).mp3 变成 my-awesome-mp3-file-some-comment-here.mp3
  • 检查文件名冲突,以便用户上传与前一个文件同名的文件时不会发生覆盖(将重复的 screenshot.png 转换为 screenshot-2.png);
  • 明确地将子文件夹的处理移至数据库,使用户目录中的文件结构保持不变。

进一步优化:

  • 将文件校验和存储在数据库中,以避免在文件系统上存储重复的文件。限制对自己的文件进行重复检查。

我写了一个社区驱动的文件共享网站,我认为它表明了这一点。 :)

If I'd do something like this, firstly I would do the following:

  • restrict the file types to a few I specify (images, mp3, mp4, maybe swf);
  • normalize the user names or restrict them to alphanumeric so that I don't have user name folder conflicts;
  • normalize the filenames so that my awesome mp3 file (some comment here).mp3 turns into my-awesome-mp3-file-some-comment-here.mp3;
  • check for file name conflicts so that if an user uploads a file with the same name as a previous one no overwriting will happen (turn duplicate screenshot.png into screenshot-2.png);
  • definitely move the handling of sub folders to the database, leaving the file structure in the user directories flat.

Further optimization:

  • store file checksums in the database to avoid storing duplicate files on the file system. Limit duplicate checking to own files.

I wrote a community driven file sharing website and I think it shows. :)

梦开始←不甜 2024-09-24 07:28:57

使用数据库是有意义的,因为只有通过界面添加的文件才可以查看(假设您正在从数据库而不是实际的文件系统中读取文件列表)。

It would make sense to use a database, as then only files added through your interface would only be available to view then (presuming you're reading the file list from a database and not the actual file system).

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