In laravel 5.2, I could upload file using below code but could not find a way to store uploaded filename in database.
$destinationPath = "test/";
$file = $request->file('profile_pic');
if($file->isValid()){
$file->move($destinationPath, $file->getClientOriginalName());
$user = User::findOrFail(Auth::user()->id);
$input = $request->all();
$input['profile_pic']->pathname = $destinationPath.$file->getClientOriginalName();
$user->update($request->all());
}
Does anyone know how to store filename in db?
Code for uploading files/images and writing real names into database
public function store(Request $request)
{
$data = $request->all();
if($file = $request->file('your_file')){
$name = $file->getClientOriginalName();
$file->move('folder_where_to_save', $name);
$data['your_file'] = $name;
}
Model_name::create($data); // where $data can be $request->all() or you can manually assign the fields you need
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With