Can the folder structure for user uploads have any impact on performance as the site grows?
For instance, I considered this structure for storing photos/albums:
Public folder
└── Uploads
└── Users
└── User ID
└── Album ID - contains all photos in the album
Thanks in advance!
Can the folder structure for user uploads have any impact on performance as the site grows?
Yes it can. If you store too many files in single directory it may slow down operations. Posted structure is very good.
Edit Maybe I was to fast with above answer and there's missing some explanations, so below I extend it:
If you expect to have tens of thousands images from users, you should consider this solution:
Create table in your database and put information about every single photo in it. Create photo filename from record id md5 hash.
Database table example:
+-----------------------------------------------------------------+ | id filename ext created_at user_id | +-----------------------------------------------------------------+ | 1 c4ca4238a0b923820dcc509a6f75849b jpg 1381127206 1 | | 2 c81e728d9d4c2f636f067f89cc14862c jpg 1381123406 2 | | .. .. .. .. | +-----------------------------------------------------------------+
Now split md5 hash and create directory structure from the first, let say, 6 letters:
uploads/ users/ photos/ c4/ ca/ 42/ c4ca4238a0b923820dcc509a6f75849b.jpg c8/ 1e/ 72/ c81e728d9d4c2f636f067f89cc14862c.jpg
Pros:
Also ensure that directory indexing is enabled on the filesystem (it's enabled by default on newer systems).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With