Storing User-uploaded Images

Posted by Nyxynyx on Pro Webmasters See other posts from Pro Webmasters or by Nyxynyx
Published on 2011-06-30T10:05:24Z Indexed on 2011/07/01 16:31 UTC
Read the original article Hit count: 250

Filed under:
|
|
|

What is the usual practice for handling user uploaded photos and storing them on the database and server?

For a user profile image:

  1. After receiving the image file from user, rename file to <image_id>_<username>
  2. Move image to /images/userprofile
  3. 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:

  1. After receiving the image file from user, rename file to <image_id>_<review_id>
  2. Move image to /images/reviews
  3. 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?

© Pro Webmasters or respective owner

Related posts about php

Related posts about mysql