Does Laravel Have A Convention For A Local Permanent Uploaded File Storage Location?

- 1 answer

I have some forms that allow the user to upload files that only they can view so I will have to store them somewhere. However, I haven't been able to find any information about where these files would usually be stored if I want them to be kept on the local server. Therefore I have to assume that there is no convention for the permanent storage location of uploaded files. Am I correct in this assumption?

To be clear, I'm not talking about temporary storage locations.

Additionally, would it be a bad idea to have the storage location of all the files as a subfolder of the app directory (with gitignore enabled on it)? Or would it be a better idea to have it outside of the app folder? Thanks!



There is no explicit convention on where to store user uploaded files.

However Laravel ships with a storage directory where it stores framework related data such as cache, sessions, etc. As the name denotes it's a good place to store files, not just framework files. Also the Laravel Filesystem Documentation mentions that the default configured location is storage/app (but that can be changed to fit your needs):

When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt: Storage::disk('local')->put('file.txt', 'Contents');

This storage/app folder will by default be ignored by Git.

If you also need the files to be publicly available, then you have two options:

1. Store them somewhere in the public directory.

2. Store them in the storage directory as suggested above and create a symbolic link to the folder from a public location. On Linux you can run this:

ln -s /path/to/laravel/public/files /path/to/laravel/storage/app/files

Of course the directory names can be whatever you like, I used files as an example.

The first option is for cases where you don't have shell access or are otherwise unable to create symbolic links. So if possible I suggest you use the second option.