7

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 /var/ directory? /srv/ directory? or maybe other directory?

4

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/www or /srv/images are fine and specified in the FHS standard while /var/www or /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.

2

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 /home/[user]/images.

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.

4
  • what about srv directory? is it better than var? – Ori Price Oct 1 '15 at 20:25
  • 2
    "Wherever you want" is exaggerated. I wouldn't for example suggest using /tmp (files will be lost at next reboot), /etc, /dev, /lost+found, /mnt, /lib, and other similar clearly dedicated to something else directories, not to mention the directories where even root is normally prevented to create regular files like /proc, /sys or /run. Finally, even if the directory is persistent, using /var/tmp would probably not be a great idea. – jlliagre Oct 1 '15 at 20:31
  • @jlliagre - the directory should be persistent. so /var/images/? /srv/images/? – Ori Price Oct 1 '15 at 20:44
  • @jlliagre - I agree that I exaggerated with "Wherever you want", because there are some locations that are obviously unsuitable. I was over-assuming preexisting *nix file system knowledge, and will update my answer to be more accurate. – rubynorails Oct 1 '15 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.