Laravel 5.2 +上传文件并将名称保存在数据库中 [英] Laravel 5.2 + upload file and save name in database
本文介绍了Laravel 5.2 +上传文件并将名称保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在laravel 5.2中,我可以使用以下代码上传文件,但是找不到在数据库中存储上传文件名的方法.
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());
}
有人知道如何在db中存储文件名吗?
Does anyone know how to store filename in db?
推荐答案
我明白了.愚蠢的错误!
I got that. Silly Mistake!!
需要替换行中的
$input['profile_pic']->pathname = $destinationPath.$file->getClientOriginalName();
到
$input['profile_pic'] = $destinationPath.$file->getClientOriginalName();
这篇关于Laravel 5.2 +上传文件并将名称保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文