I am working with PHP Laravel 8. I am doing avatar upload to the database and uploading it to public/assets. It's working with database but it doesn't upload it I want some help Thank You
This is HTML code for uploading
<div class="form-group">
<label for="exampleInputFile">Profile Image</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="profile_image" class="custom-file-input" id="profile-image">
<label class="custom-file-label" for="exampleInputFile">Recommended Profile Image (160w x 160h)</label>
</div>
</div>
<span class="font-italic text-warning">Picture size should be less than 4MB</span>
</div>
@tykus it's not uploading the image ... can you tell me if I need any image package for this ? I searched it and nothing worked in this issue I don't know why it happened
@tykus yeah it has multipart/form-data ... and I not getting any Exception its saving and return success but not uploading it to folder and when I remove this line before If condition which you removed
@hamzajamshed152 when the input is a file type; then $request->input('profile_image') will be null - so how was this working previously? Do you have another (text) input on the form with name profile_image?
`
@Snapey Thank you .. i think i just type it in a hurry
but one more error comes up tykus change this code and this code come up with ErrorException
Undefined variable:$image can you check this for me please
public function update(Request $request)
{
$user = auth()->user();
$user->full_name=$request->input('full_name');
$user->email=$request->input('email');
$user->avatar=$request->input('profile_image');
if ($request->hasFile('profile_image')) {
$avatar = $request->file('profile_image');
$filename = now()->timestamp . '.' . $avatar->getClientOriginalExtension();
$image->move(public_path('assets/uploads/images/'), $filename);
Image::make($avatar)->resize(300, 300)->save($image);
$user->avatar = $location;
}
$user->save();
return redirect()->back()->with('success','Sucessfully changed User Information');
}
@Snapey I checked this code previously but it's not updating in the database so I add one line I removed it but it makes ErrorExpection of Undefined variable $image also