user file storage

  • Kurthead+1
  • Graduate
  • Graduate
  • Kurthead+1
  • Posts: 130

Post 3+ Months Ago

Using PHP still. For now.

If a user uploads a profile image, that will be attached to their forum posts etc, where is the best place to store this profile image?

Is it best to create a new folder for EVERY user that stores their images etc? I kind of felt creating a new folder for every user is a little bit too fragile. Or is there a better way? I want to do this from scratch, no CMS systems.

People just list your suggestions on how you handle this when building a website. Thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 448

Post 3+ Months Ago

I would make (Guessing this is a small load site) one folder to hold the profile images.

I'm also assuming you have a database so in the record that your going to attach the file name to. I would hash I used md5 the user id and microtime to create a random filename that will not over write other files. (this next part is optional) I would then save the original file name this would be used to make the file name nicer on the user if there was a download feature this is completely optional though.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Usually what I would do (simplified) would be to take a hash of the file and save it to a folder with the hash as its name. Then related the hash to the user in a database.

On a more complicated level, I would build a hierarchy of folders. The first level related to the first two characters of the has, the second level relates to the next to characters, splitting off two characters of the file name into folders for X folder levels.

The last little bit wont matter for a smaller site.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 448

Post 3+ Months Ago

Do you read only a portion of the file or the whole thing to create your hash?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Well the entire file is sent you. So you could do a hash of the entire file. However, the first X bytes + a timestamp of file upload would give you something unique. It also depends on if you want to only store a single instance of any given file.

If you hash the entire file, you will only ever store a single instance of that file. This is how most storage service work such as dropbox and the mega* sites.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 448

Post 3+ Months Ago

I've always have hashed some info of the uploader and a microtime to not have any over write issues. So there could be the same file across multiple users. I never really thought about hashing the uploaded file info. since I abide by the rule that nothing should be deleted this method would work well and help limit duplications.
  • Kurthead+1
  • Graduate
  • Graduate
  • Kurthead+1
  • Posts: 130

Post 3+ Months Ago

I like the idea of putting all user images in one folder, then using mySQL to recall the correct image name. I'll probably just write a little script in php to attach an incrementing number at the end of each image file, so they will never overwrite or have conflicting filenames. I like to use outside sources as little as possible. Do you think that'll hold up?

Just have the php script scan the directory, explode the number off of the last filename and increment to it and attach it to the new file. Ensuring they never have the same name.

(I'm not sure how large this site will end up being. How many users or w/e)

But backend includes, registered users, profile images, forum posts, profile information, custom CMS to change elements of the site, manage user information and control the public forums. User story/novel submissions. I guess it's a medium sized site.
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

I usually throw mine into a longblob in mysql itself. Yes, I'm lazy, so what?

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: spork and 86 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.