There is a whole section of files section in the documentation for requests, also a section on file uploads on the filesystem documentation you might wanna look at, that could give you some help. 🙂
Jan 19, 2021
4
Level 5
Image Upload Not working
When I try to upload an image, it creates the image name as a folder and then a .tmp file in the folder. Not sure what I did.
if($request->hasfile('avatar'))
{
$destination = 'uploads/profile/'.$user->avatar;
if(File::exists($destination)){
File::delete($destination);
}
$file = $request->file('avatar');
$extension= $file->getClientOriginalExtension();
$filename = time() . '.'.$extension;
$file->move('uploads/profile/'.$filename);
$user->avatar = $filename;
}
Level 7
For most of the cases, laravel has a pretty straight forward method to store file.
$path = $request->file('avatar')->store('avatars');
Docs here: https://laravel.com/docs/8.x/filesystem#file-uploads
1 like
Please or to participate in this conversation.