cheese5505
cheese5505

Reputation: 982

Uploading and storing file with Laravel

I am using Laravel illuminate/html and I am trying to upload an image file and store it in /public in the laravel installation folder. I have got the image from the request:

$img = Request::file('img');

How can I store it in the public folder?

Thanks

Upvotes: 0

Views: 463

Answers (1)

Emeka Mbah
Emeka Mbah

Reputation: 17545

You could do this in your controller:

Request::file('img')->move(base_path('public/uploads'));

Or if you wish to specify a generic filename or change filename

$newfilename = str_random(32) .time();

 $ newfilename = $newfilename. ".". Request::file('img')->guessClientExtension();



 Request::file('img')->move(base_path('public/uploads'), $newfilename);`

Upvotes: 1

Related Questions