图片上传腾讯云存储

function cosPub($path){
        $cosClient = new Client(
            array(
                'region' => 'ap-chengdu',
                'credentials'=> array(
                    'secretId'  => env('QCLOUD_COS_SECRET_ID'),
                    'secretKey' => env('QCLOUD_COS_SECRET_KEY')
                )
            )
        );
        try {
            $bucket = "";
            $key = '/houtai/' . md5(time()) . '.' . 'jpg';
            $srcPath =$path;
            $result = $cosClient->putObject(array(
                'Bucket' => $bucket,
                'Key' => $key,
                'Body' => fopen($srcPath, 'rb')));
            $res = res(200, ['url'=>$result['ObjectURL']]);
        } catch (\Exception $e) {
            $res = res(403, [], '文件上传失败');
        }

        return $res;
    }

  

posted @ 2019-08-12 09:56  冷空气的清晰  阅读(298)  评论(0编辑  收藏  举报