Uploading photos to linux server via php - what is the max number of files a folder can have?

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?

Answers


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.


@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...


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:

df -i

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


Need Your Help

How to keep only single form open in delphi

delphi

I have VCL application in delphi. One main form and many child forms.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.