douyan7916
2016-05-09 06:51
浏览 230
已采纳

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());
    }

Does anyone know how to store filename in db?

图片转代码服务由CSDN问答提供 功能建议

在laravel 5.2中,我可以使用下面的代码上传文件,但找不到在数据库中存储上传文件名的方法。

  $ 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中存储文件名?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

  • duanna2026 2016-05-09 07:04
    最佳回答

    I got that. Silly Mistake!!

    need to replace line from

    $input['profile_pic']->pathname = $destinationPath.$file->getClientOriginalName();
    

    to

    $input['profile_pic'] = $destinationPath.$file->getClientOriginalName();
    
    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题