79
votes

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.

5

5 Answers

76
votes

In Laravel 3, call path('storage').

In Laravel 4, use the storage_path() helper function.

78
votes

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');
28
votes

For Laravel version >=5.1

storage_path()

The storage_path function returns the fully qualified path to the storage directory:

$path = storage_path();

You may also use the storage_path function to generate a fully qualified path to a given file relative to the storage directory:

$app_path = storage_path('app');
$file_path = storage_path('app/file.txt');

Source: Laravel Doc

4
votes

use this artisan command for create shortcut in public folder

php artisan storage:link

Than you will able to access posted img or file

0
votes

You can use the storage_path(); function to get storage folder path.

storage_path(); // Return path like: laravel_app\storage

Suppose you want to save your logfile mylog.log inside Log folder of storage folder. You have to write something like

storage_path() . '/LogFolder/mylog.log'