php - User uploads folder structure -
can folder structure user uploads have impact on performance site grows?
for instance, considered structure storing photos/albums:
public folder - uploads -- users --- user id ---- album id - contains photos in album
thanks in advance!
can folder structure user uploads have impact on performance site grows?
yes can. if store many files in single directory may slow down operations. posted structure good.
edit maybe fast above answer , there's missing explanations, below extend it:
if expect have tens of thousands images users, should consider solution:
create table in database , put information every single photo in it. create photo filename 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 , create directory structure first, let say, 6 letters:
uploads/ users/ photos/ c4/ ca/ 42/ c4ca4238a0b923820dcc509a6f75849b.jpg c8/ 1e/ 72/ c81e728d9d4c2f636f067f89cc14862c.jpg
pros:
- you not exposing directory structure users.
- it's easy find file name.
- information files stored in database it's easy sort, group ect.
also ensure directory indexing enabled on filesystem (it's enabled default on newer systems).
Comments
Post a Comment