laravel上传图片

    public function uploadFilePrivate(Request $request)
    {
        $file = array_get($request, 'file', '');
        if (empty($file)) {
            return $this->responseJson([], -1, '文件不能为空');
        }

        $data = [
            'file' => new \CURLFile($file->getPathname(), $file->getClientMimeType(), $file->getClientOriginalName()),
        ];

        try {
            $result = Gateway::tool('/v1/file/private', $data, 'POST');
            $result['origin_name'] = $file->getClientOriginalName();
            return $this->responseJson($result);
        } catch (\Exception $e) {
            return $this->responseJson([], '-1', '上传失败');
        }
    }

 

posted @ 2020-04-23 18:02  泥土里的绽放  阅读(251)  评论(0编辑  收藏  举报