Leo Wttr
Leo Wttr

Reputation: 3

How to access stored file in Laravel with Filesystem?

I'm trying to rename an existing file which is saved in my storage directory but when I try to access it in any ways, I get "File not found".

I try accessing it with Storage::get method and storage_path method but both of them returns file not found.

Here is my local driver in filesystems.php:

'local' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
        ],

Here is my code:

Storage::move(storage_path('app/public/'.$document->name), $request->get('rename'));

Here is my error:

File not found at path: home/vagrant/code/storage/app/public/myFile.pdf

The file exists at the location and I can't find the issue.

Upvotes: 0

Views: 464

Answers (1)

Jerodev
Jerodev

Reputation: 33186

You already defined the path to your storage in your config, there is no need to provide the root path again.

Storage::move($document->name, $request->get('rename'));

And if local is not your default provider, you should select this disk:

Storage::disk('local')->move($document->name, $request->get('rename'));

Upvotes: 1

Related Questions