How to put other image extensions in Laravel 5.2? -
i have solution upload image of user profile picking storage folder working. question how can play extension of image bank or how can validate in controller other extensions can me?
controller
public function getaccount() { return view('account', ['user' => auth::user()]); } public function postsaveaccount(request $request) { $this->validate($request, [ 'email' => 'required|email|max:100' ]); $user = auth::user(); $old_email = $user->email; $user->email = $request['email']; $user->update(); $file = $request->file('image'); $file_email = $request['email'] . '-' . $user->id . '.jpg'; $old_file_email = $old_email . '-' . $user->id . '.jpg'; $update = false; if (storage::disk('local')->has($old_file_email)) { $old_file = storage::disk('local')->get($old_file_email); storage::disk('local')->put($file_email, $old_file); $update = true; } if ($file) { storage::disk('local')->put($file_email, file::get($file)); } if ($update && $old_file_email !== $file_email) { storage::delete($old_file_email); } return redirect()->route('account'); } public function getuserimage() { $user = auth::user(); $image ="". $user->email . '-' . $user->id . '.jpg'; $file = storage::disk('local')->get($image); return response::make($file,200,[ 'content-type' => 'image/jpeg']); }
route
route::get('/account', [ 'uses' => 'usercontroller@getaccount', 'as' => 'account' ]); route::post('/upateaccount', [ 'uses' => 'usercontroller@postsaveaccount', 'as' => 'account.save' ]); route::get('/userimage', [ 'uses' => 'usercontroller@getuserimage', 'as' => 'account.image' ]);
view
<img src="{{ route('account.image')}}">
repository gitlab https://gitlab.com/ronnyere/imageuploadlaravel.git
i recommend use 1 extension store uploaded images
to encode of possible image extensions 1 extension, can use intervention image
you can change extension of of uploaded images using...
image::make($request->file('image')->getrealpath())->encode('jpg');
you can change jpg
extensions well
Comments
Post a Comment