Skip to content
Advertisement

Systematic way to store pictures for social website [closed]

I’m building a basic social website where users can upload pictures. I’m going to store store the images on the file system. When a user uploads a picture, how do you think I should name the files? I don’t want to simply label the pictures sequential numbers so I was thinking about *userid_dateinseconds_width.jpg*.

Also, I’ll need to store information about each picture in the database — such as who it belongs to, what photo album it’s in, etc. How would you recommend structuring the database table to do so?

Advertisement

Answer

I like Naterade’s answer but there is one concern that I see. When you name the files in this way you are exposing the internals of your system (the ids that you use) to anyone who can view the image. Facebook used to name their images in such a way that the user id was part of the image path — the result was that if someone saved and reposted an image from facebook, by looking at the file name people could track down who it was in the picture. I would suggest such a naming scheme but then put it through a hash.

Using a hash can also help you get around the problem PeeHaa mentions of having limited number of files in a directory. You can hash the file name then take the first letter or two letters as a directory and thus split the images reasonably equally between 26 or 26^2 directories depending on how many images you have. Good luck.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement