1
votes

I'm trying to upload images to the storage/app/public/ folder that is linked to the public folder from Laravel. My filesystems.php is configured this way:

'default' => env('FILESYSTEM_DRIVER', 'public')
//rest of the code
        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

And at my controller, I upload the image:

$file = $request->hasFile('imagem');
$file = $request->file('imagem')->isValid();

$upload = $request->imagem->store('instituicoes');

I want the file to be uploaded to this path storage/app/public/instituicoes but when I use this code Laravel creates the 'instituicoes' folder at the storage/app folder, not at the storage/app/public/ that I defined as storage path. Laravel Folders

2
Have you linked your storage folder by php artisan storage:link ?!Soheil Rahmat
Couple days ago someone else wanted to remove storage word from URL. I offered this solution, but I think it could give you idea what you need to do to set other location than storage/app/public for linking.Tpojka
I used php artisan storage:linkNatan Rocha Batista
What's the value of your FILESYSTEM_DRIVER environment variable? If it's not public, then you're not storing to the public disk by defaultTravis Britz
It's public. It's the first line of code I showed at the question.Natan Rocha Batista

2 Answers

1
votes

Since your default disk is using the FILESYSTEM_DRIVER environment variable, make sure that the value of the variable is set to public as your default disk. It looks like it might be using your local disk instead.

You could also try changing this:

$upload = $request->imagem->store('instituicoes');

to this:

$upload = $request->imagem->store('instituicoes', 'public');

to force using the public disk instead of whatever the default is.

0
votes

From https://laravel.com/docs/5.7/filesystem

The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public.

To create the symbolic link, you may use the storage:link Artisan command:

php artisan storage:link