$region, 'schema' => $schema, //协议头部,默认为http 'credentials'=> array( 'secretId' => $secretId , 'secretKey' => $secretKey ) ) ); $bucket = C("cos_storage.bucket"); //存储桶名称 格式:BucketName-APPID $key = $dst; $srcPath = $src;//本地文件绝对路径 try { $result = $cosClient->Upload( $bucket = $bucket, $key = $key, $body = fopen($srcPath, 'rb') ); $location = $result['Location']; if(!preg_match('/^(http)|(https)/', $location)) { $result['Location'] = 'https://' . $result['Location']; } return $result['Location']; } catch (\Exception $e) { $this->error($e->getMessage()); } } }