Storing User-uploaded Images
- by Nyxynyx
What is the usual practice for handling user uploaded photos and storing them on the database and server?
For a user profile image:
After receiving the image file from user, rename file to <image_id>_<username>
Move image to /images/userprofile
Add img filename to a table users containing their profile details like first_name, last_name, age, gender, birthday
For a image for a review done by user:
After receiving the image file from user, rename file to <image_id>_<review_id>
Move image to /images/reviews
Add img filename to a table reviews containing their profile details like review_id, review_content, user_id, score.
Question 1: How should I go about storing the image filenames if the user can upload multiple photos for a particular review? Serialize?
Question 2: Or have another table review_images with columns review_id, image_id, image_filename just for tracking images? Will doing a JOIN when retriving the image_filename from this table slow down performance noticeably?
Question 3: Should all the images be stored in a single folder? Will there be a problem when we have 100K photos in the same folder?
Is there a more efficient way to go about doing this?