首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel Passport API上传多张图片

Laravel Passport API上传多张图片
EN

Stack Overflow用户
提问于 2019-11-25 11:27:45
回答 1查看 230关注 0票数 1

目前,我只使用Laravel Passport API上传一张图片

我有这个代码,它工作得很好。

代码语言:javascript
复制
        //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,它工作得很好

现在我正在尝试在一个单一的请求中进行多个图像上传。对于这段代码,这是可能的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-25 11:48:24

yes可以用你的代码做同样的事情

在邮递员中,多次将名称作为file[]传递

代码语言:javascript
复制
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!"
    ]);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59024881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档