Reputation: 179
I'm using the Image Intervention package in Laravel and I can't display my profile image. The problem is that the browser fails to load the resource
localhost:8000/uploads etc.
All files are saved in public folder :
public/uploads
My view:
<div class="row">
<div class="col-md-2 ">
<img src="uploads/{{ $user->avatar }}">
</div>
</div>
Controller:
class UserController extends Controller
{
public function profile()
{
return view ('user.profile', array('user'=>Auth::user()));
}
public function update(Request $request)
{
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300, 300)->save(public_path('/uploads/avatar' . $filename));
$user = Auth::user();
$user->avatar = $filename;
$user->save();
}
return view('user.profile',array('user'=>Auth::user()));
}
}
I'm using windows and i see these files saved in my folder public/uploads but i cant display it
Regards
Upvotes: 0
Views: 1689
Reputation: 70
When you save the image, add a /
after "uploads/avatar":
save(public_path('/uploads/avatar/' . $filename));
That should solve the naming problem. Then in your HTML add "avatar/" after "uploads/", as you are saving to the "upload/avatar" folder.
Then your view would look like this:
<div class="row">
<div class="col-md-2 ">
<img src="uploads/avatar/{{ $user->avatar }}">
</div>
</div>
Upvotes: 2
Reputation: 7899
In your controller class change this line:
$user->avatar = $filename;
to this:
$user->avatar = 'avatar' . $filename;
Upvotes: 1