I know that somewhere in the history of the internet this must have been asked somewhere, but I just can't seem to nail down the right terminology to get the answer I need. This question comes close: What is the best way to store user uploaded files in a website? But I need a little bit more detail.
Basically, how are you supposed to effectively manage files that users have uploaded, such as a profile picture? What I want to know are some "best practices" regarding WHERE to make the directory structure.
The second answer in the above question offers some options, such as storing them outside of the web root, which is what I originally thought about doing. But then I started thinking...
1) How do we save the paths in the database? Absolute? Relative? Each user has a column for "ProfilePicPath". What if we want to completely uproot the entire project from one server to another, and for whatever reason we can't put the files in the same place on the new server? Every link would be broken.
2) How should this be handled in terms of security? Say we have our web application deployed to like C:\websites\site1, but we store the user profile pictures in like C:\usercontent\profilepictures\? On a page where we load the profile picture, how do we safely access that programmatically in the code behind? We don't want to put them in like C:\websites\site1\usercontent\profilepictures\, right? I'm not a fan of putting an absolute path into the database, and I also don't want to hardcode a path in anywhere in the code behind.
We originally DID try with the files inside the web project, but then it became kind of a risk, because these user files were part of our project. One wrong copy/paste when updating/modifying the site and we might overwrite a file a user has uploaded since we last checked out the project from the repository, etc. It was a huge hassle, and the whole scenario just screamed to me, "you idiot, you're doing this all wrong..." but I just can't seem to find a proper guide to doing it "right."
Just to be clear, our needs are minimal --- this is just a small project for internal use, no more than maybe 30 users, and it all needs to be contained on one IIS 7 server.