我正在使用 Laravel 5 和 MongoDB 构建一个 Restful API。我正在为用户保存头像。它工作正常,但我正在尝试为每个用户创建一个文件夹。例如:"app/players/images/USERID"
我试图以不同的方式做这样的事情,但我总是得到不支持 Driver [] 。
\Storage::disk('players'.$user->id)->put($image_name, \File::get($image));
上传图片:
public function uploadImage(Request $request)
{
$token = $request->header('Authorization');
$jwtAuth = new \JwtAuth();
$user = $jwtAuth->checkToken($token, true);
$image = $request->file('file0');
$validate = \Validator::make($request->all(), [
'file0' => 'required|image|mimes:jpg,jpeg,png'
]);
if ( !$image || $validate->fails() )
{
$data = array(
'code' => 400,
'status' => 'error',
'message' => 'Image uploading error-'
);
}
else
{
$image_name = time().$image->getClientOriginalName();
\Storage::disk('players')->put($image_name, \File::get($image));
$user_update = User::where('_id', $user->id)->update(['imagen' => $image_name]);
$data = array(
'code' => 200,
'status' => 'success',
'user' => $user->id,
'imagen' => $image_name
);
}
return response()->json($data, $data['code']);
}
文件系统.php:
'players' => [
'driver' => 'local',
'root' => storage_path('app/players/images/'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
我希望用户头像图像保存在用户 ID 文件夹中。
茅侃侃
慕桂英4014372