Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd store images by user. However, given that you potentially have a lot of users, it may not be that simple.</p> <p>User file uploads are just that: user-specific file uploads. When you manage these files you often need to apply various procedures per-user. For example: 1) remove user account and delete all related files, 2) calculate amount of space a user uses, 3) list all files a user has uploaded, etc. </p> <p>If you scatter these files across various directories it is much harder to efficiently implement the above procedures.</p> <p>You specified that you may have more than 100.000 users. Depending on what your filesystem is, you may end up having troubles because of this. For instance in ext3, there is maximum of 32K subdirectories per directory, which can be a problem for organizing the files in directories per user (see: <a href="https://stackoverflow.com/questions/466521/how-many-files-in-a-directory-is-too-many">How many files can I put in a directory?</a>).</p> <p>Assuming that we cannot store more than 32K files or directories inside a directory then you would need to find out a way to work around this limit. For instance, you can split user folders into several subdirectories according to the first letter in username (and add an extra subdir for all the other starting characters):</p> <pre><code>users a aaron ... b bertie ... ... misc _foobar ... @jack ... </code></pre> <p>Now you only have roughly <code>100000/25=4000</code> users per directory, which is under the given 32K.</p> <p>Thinking outside of the box, <em>it may not be the right choice to store the images as files in a flat filesystem</em>. There are database systems that are specifically created for storing and handling large numbers of files. Take <a href="https://stackoverflow.com/questions/4988436/mongodb-gridfs-with-c-how-to-store-files-such-as-images">MongoDB's GridFS for instance</a>. It is very efficient and scales to large number of files, also taking care of all the lower-level issues like correct filesystem usage. In MS SQL there is <a href="http://technet.microsoft.com/en-us/library/bb933993%28v=sql.105%29.aspx" rel="nofollow noreferrer">the FILESTREAM Storage</a>, which is specifically good at storing files on an NTFS filesystem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload