Question: 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?

Answer: 
@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](http://en.wikipedia.org/wiki/Ext3#Size_limits) 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