Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel saving image to public folder?

So I am trying to save uploaded image to laravel/public folder and return src so a path to where the file has been saved, however nothing happens after I choose an image and I get no errors, what might be wrong?

public function testing(Request $request) {
    if(Input::file())
    {
        $image = Input::file('img');
        $filename = time() . '.' . $image->getClientOriginalExtension();
        $path = public_path('images/' . $filename);
        Image::make($image->getRealPath())->resize(200, 200)->save($path);
        $user->image = $filename;
        $user->save();
    }
}


<form action="{{ action('BuilderController@testing') }}" enctype="multipart/form-data" role="form" method="POST">
    <input id="img" class="form-control filestyle margin images" data-input="false" type="file" data-buttonText="Upload Logo" data-size="sm" data-badge="false" onchange="uploadImage();" />
</form>
like image 617
Przemek Avatar asked Mar 06 '17 11:03

Przemek


1 Answers

Try with move() method?

$filename = time().'.'.request()->img->getClientOriginalExtension();
request()->img->move(public_path('images'), $filename);

$user->image=$filename;
$user->save();
like image 131
Sanzeeb Aryal Avatar answered Nov 07 '22 11:11

Sanzeeb Aryal