欢迎各位兄弟 发布技术文章
这里的技术是共享的
private function save_user_logo($request,$user){
if($request->hasFile('user_logo')){
$file = $request->file('user_logo');
if($file->isValid()){
// 获取文件相关信息
$originalName = $file->getClientOriginalName(); // 文件原名
$ext = $file->getClientOriginalExtension(); // 扩展名
$realPath = $file->getRealPath(); //临时文件的绝对路径
$type = $file->getClientMimeType(); // image/jpeg
$filename = Carbon::now()->format('Y-m-d-H-i-s').'-'.substr(sha1(mt_rand()), 0, 10).'.'.$ext;
$pathname = date('Y-m').'/'.$filename;
// 使用我们新建的uploads本地存储空间(目录)
$bool = Storage::disk('uploads')->put($pathname, file_get_contents($realPath));
if($bool){
$user->user_logo = $pathname;
$user->user_logo_original = $originalName;
}
}
$user->save();
}
}
public function store(UserRequest $request)
{
//
$user = new User();
$user->create($request->all());
$this->save_user_logo($request,$user);
return redirect('admin/users');
}