i am building a webpage where a the user can upload images. i am going to use the file-system to store my images. i was wondering what is the best directory to hold such data? is it
/srv/ directory? or maybe other directory?
There are several factors to consider before choosing a directory path. The best directory is the one that has enough capacity to store the expected volume of files, that has the right level of protection and finally that has no risk to be overwritten or messed by standard packages.
/srv/images are fine and specified in the FHS standard while
/var/images are not recommended:
Applications must generally not add directories to the top level of /var. Such directories should only be added if they have some system-wide implication, and in consultation with the FHS mailing list.
Store them wherever you want! If it's your file system, then it's your preference. Just make sure you have the correct permissions in place.
Edit: As @jlliagre stated below, the above is an exaggeration, as there are some file system locations that would be absolutely unsuitable for storing these images.
If you have multiple users and you want them to each have their own image directory, I would suggest something such as
If you want all of these images to be easily-accessible within a single directory, then I would do something such as
/var/www/img/user_uploads/[user] (or something similar, depending on OS).
Permissions are key though, because you want to maintain the correct level of access for each user and the worker process while limiting public access to that which should remain private to each user.
By default, there will be certain directories that have public permissions that get inherited to child directories. So if you store these images in
/home/[user]/public_html/images, then the whole Internet would have access to these images unless you took the necessary steps to prevent that behavior.
That being said, if you store them in a private directory such as
/home/user/images, then the web server process/user would need explicit permission to access that directory.