目前,我只使用Laravel Passport API上传一张图片
我有这个代码,它工作得很好。
//Saves file to public folder
$dateTime = date('Ymd_His');
$file = $request->file('file');
$fileName = $dateTime . '-' . $file->getClientOriginalName();
$savePath = public_path('/upload/img/');
$file->move($savePath, $fileName);
//This saves the current file path of image to mytable
$ActivityLog = new ActivityLogImg;
$ActivityLog->actCode = $activity_code;
$ActivityLog->projCode = $request->projCode;
$ActivityLog->attachment = "/upload/img/".$fileName;
$ActivityLog->type = "IMAGE";
$ActivityLog->deleted = 0;
$ActivityLog->created_by_id = Auth::user()->company_id;
$ActivityLog->created_by_name = Auth::user()->name;
$ActivityLog->created_at = now();
$ActivityLog->updated_at = now();
$ActivityLog->save();
return response([
"status"=>"ok",
"message"=>"Activity successfully submitted!"
]);我收到了邮递员的请求来测试api,它工作得很好


现在我正在尝试在一个单一的请求中进行多个图像上传。对于这段代码,这是可能的吗?
发布于 2019-11-25 11:48:24
yes可以用你的代码做同样的事情
在邮递员中,多次将名称作为file[]传递
foreach($request->file('file') as $file){
$dateTime = date('Ymd_His');
$fileName = $dateTime . '-' . $file->getClientOriginalName();
$savePath = public_path('/upload/img/');
$file->move($savePath, $fileName);
//This saves the current file path of image to mytable
$ActivityLog = new ActivityLogImg;
$ActivityLog->actCode = $activity_code;
$ActivityLog->projCode = $request->projCode;
$ActivityLog->attachment = "/upload/img/".$fileName;
$ActivityLog->type = "IMAGE";
$ActivityLog->deleted = 0;
$ActivityLog->created_by_id = Auth::user()->company_id;
$ActivityLog->created_by_name = Auth::user()->name;
$ActivityLog->created_at = now();
$ActivityLog->updated_at = now();
$ActivityLog->save();
}
return response([
"status"=>"ok",
"message"=>"Activity successfully submitted!"
]);https://stackoverflow.com/questions/59024881
复制相似问题