通过 php 将照片上传到 Linux 服务器 - 一个文件夹最多可以包含多少个文件?
我正在创建一个允许用户上传照片的网站。这是一个Linux服务器。
我想知道保存这些图像的最佳目录结构是什么?一个文件夹可以包含的文件数量是否有限制?
将每个用户上传的每张照片保存到一个文件夹中并在数据库中提供每张照片的参考是不是更好?或者为每个用户创建一个文件夹并在其中包含他们的所有照片?
I'm creating an site which allows users to upload photos. It's a linux server.
I was wondering what would be the best directory structure to to save these images? And is there a limit of number of files a folder can have?
Would it be better to save every photo uploaded by every user to one single folder and have a reference of each in the database. Or create a folder for each user and have all of their photos in it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@OP,目录可以通过几种方式具有所谓的“限制”。一是是否设置了磁盘配额。另一个取决于文件系统。例如,在这篇文章中,它说ext3有
有一个限制每个目录有 31998 个子目录,源于每个 inode 32000 个链接的限制。
您可以通过进一步搜索找到其他文件系统的这些信息。例如,ReiserFS 每个目录最多可以处理 2^31 个,依此类推...
@OP, there a few ways that a directory can have so called "limits". One is if disk quota is set. The other depends on filesystem. For example in this article, it says ext3 has
There is a limit of 31998 sub-directories per one directory, stemming from its limit of 32000 links per inode.
You can find these information for other file systems with further searching. eg ReiserFS can handle up to 2^31 per directory and so on...
文件可能没有限制,但根据文件系统,您希望将目录中的文件数量限制在 1,000 到 10,000 之间。如果您的文件系统不索引目录,即使有 1,000 个文件也会使文件操作变慢。
如果您的文件系统对目录进行索引,那么您可以轻松地将 100,000 个文件集中在一个文件系统中,但您并不想这样做。即使在包含 1k 个文件的目录上执行 ls -l 也会很慢;在它开始在包含 100k 文件的目录上输出之前,您可能会放弃。
如果不会有太多用户,那么每个用户有一个目录是个好主意。如果有大量用户(超过 1k),我建议在创建新目录之前将文件存储在每个最多包含 1k 个文件的目录中。
There is probably no limit on files, but depending on the filesystem, you want to limit the number of files in a directory to between 1,000 and 10,000. If you have a filesystem that doesn't index directories, even having 1,000 files is going to make file operations slow.
If your filesystem does index directories, you could easily have 100,000 files in one, but you wouldn't want to. Doing an
ls -l
on a directory with even 1k files is going to be slow; you would probably give up before it even started outputting on a directory with 100k files.If there aren't going to be too many users, having a single directory per user is a good idea. If there are going to be lots of users (over 1k), I would recommend storing the files in directories of up to 1k files each before creating a new directory.
Linux 中目录可以容纳的文件数量的唯一限制是可用 inode 的数量。您可以通过执行以下命令来确定该数字:
报告为 IFree 的数字是目录中可以保存的文件数量的上限,但请注意该数字适用于整个文件系统。因此,如果您将最大数量的文件放入一个目录中,您将无法在文件系统的其他任何位置创建更多文件。
每个用户的目录是可行的方法
The only limit to the number of files a directory can hold in linux in the number of free inodes. You can determine this figure by executing:
The figure reported as IFree is the upper bound on the number of files you can hold in a directory, but be aware that this figure is for the whole filesystem. So if you put the maximum number of files in one directory, you will not be able to create any more files anywhere else in the filesystem.
A directory for each user would be the way to go