1
Laravel 5.2 + download the file and save the name in the database
source link: https://www.codesd.com/item/laravel-5-2-download-the-file-and-save-the-name-in-the-database.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Laravel 5.2 + download the file and save the name in the database
advertisements
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?
You can try this, It wiil help you:
$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()); // Remove This
// Add this lines
$data['YOUR_DB_FIELD_NAME'] = $file->getClientOriginalName();
$user->update($data);
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK