I want to store uploaded images to my Laravel-based web app in a subdirectory of the Laravel storage
directory. It's the directory at the same hierarchy level as the 'application' and 'public' directories.
Is there a framework method for doing this? I've searched the docs but can't find one.
Laravel's filesystem configuration file is located at config/filesystems.php . Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.
Laravel provide several helper to get path of public directory, app directory, storage directory and base directory. It will help to store files, read file from path and also for other from controller, view files, model etc. You can see as bellow how to get path of that directory using helper one by one.
Now, if you need to change the directory and store into the storage folder directly, you need to change something in the filesystems. php file. 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), ], Here, this line of code 'root' => storage_path('app'), responsible to define where to store.
You can link the storage folder in laravel using php artisan command and you can also run a PHP script to create a symbolic link between two folders.
In Laravel 3, call path('storage')
.
In Laravel 4, use the storage_path()
helper function.
For Laravel 5.x, use $storage_path = storage_path()
.
From the Laravel 5.0 docs:
storage_path
Get the fully qualified path to the
storage
directory.
Note also that, for Laravel 5.1 and above, per the Laravel 5.1 docs:
You may also use the
storage_path
function to generate a fully qualified path to a given file relative to the storage directory:$path = storage_path('app/file.txt');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With