Bad idea to create a folder for each user?

I am wondering if it would be a bad idea to create a folder for each user. Thus, any images for each user will be available using img.mysite.com/UserId/image.jpg

+4
source share
7 answers

This can become a huge number of directories, so be careful, as some file systems limit the number of subdirectories in a single directory. Usually split generated content into multiple directories. You can do this by date or break down some identifier (hash or auto-incrementing image identification number) to create a deeper directory structure. Example:

  • avatars / 000 / (images 1-999)
  • Avatars / 001 / (Images 1000-1999)
  • Avatars / 002 / (Images 2000-2999)

AKA floor(ID / 1000) directory prefix floor(ID / 1000) .

Probably in any case to abstract your URIs from your file system, so it really doesn't matter where the files are stored on the server except you as a programmer.

+4
source

Absolutely Bad Idea I Will Tell From My Experience
Recently, I have been working on one application based on social networks. And now it has about 15,000 users.

I am also managing this site currently.

Problems with this - it will be great to manage at first, but later it will be a problem.
Always keep track of permissions.
Create and delete folders in relation to your database to achieve synchronization.
In addition, if you are on a shared hosting, many hosting providers do not show all folders with any file manager. The maximum number of folders that can be seen through File Managers is 2000 with client support, you only get access to the first folder 10000. Also, the name Non-Ascii for the folder will be, like for the database, another problem.

This will be a big problem for you later.

I suggest not going that way for sure.

+5
source

No, this is not a good idea.

If the sole purpose of individual folders is to allow you to have β€œfriendly” URLs in the structure you propose, I recommend that you rewrite the URLs instead.

If you are trying to solve some other problem, post a comment and let us know.

+1
source

There is no reason why this could be a problem due to performance. From an organizational point of view, it’s cleaner than just dropping them together in the same folder.

+1
source

I think this would be the best format:
http://img.mysite.com/userid_imageid.jpg

Then you can make the database as follows:

users and imgs

0
source

Use one folder on your ftp and create a good and solid database where all the photos of the same person are connected to each other. Not so hard :)

0
source

For a small site, this is not a scary idea, with one caveat:

You MUST abstract the file creation / deletion processing in one mechanism!

Make sure that all of your code uses this mechanism, which should be able to store, retrieve, and delete, and that it is. Then, in the future, if you want to change the way you store your files, you can do this very easily.

PS When I say all your code, I really mean all your code. For example, I will have a GET that matches

 ^img.mysite.com/(\w+)/(\w+\.jpg)$ 

It is processed by one method, which calls the mechanism described above.

0
source

All Articles