Programador Adagal
Programador Adagal

Reputation: 780

Laravel 5.1 - Move uploaded file

I am trying to upload to the server a photo avatar. I have an ajax function that works correctly and uploads a photo to a tmp folder. The controller returns the original name and the tmp file path and saves to hidden fields.

What I need is when I save the model, move the tmp file from the tmp folder to the avatars folder (created by me inside public/images/avatars).

I have tried with Storage::get($input['file_to_move'])and get a FileNotFoundException (although the file really exists). How can I get a var $file with the file to do $file->move($avatars_path).

Thanks In advance.

Upvotes: 0

Views: 2084

Answers (1)

Amir Bar
Amir Bar

Reputation: 3105

the problem is the default local disk point to the storage directory..

open config>filesystem inside disks array insert this:

        'public' => [
            'driver' => 'local',
            'root' => public_path(''),
        ],

now do this

Storage::disk('public')->get($input['file_to_move'])

Upvotes: 3

Related Questions