1-安装腾讯云SDK
composer require qcloud/cos-sdk-v5
2-腾讯云配置

<?php
namespace app\common\controller;
use Qcloud\Cos\Client;
use think\Controller;
use think\Db;
class Tencent extends Controller
{
/**
* 上传文件
* @param $config
* @param $key
* @return array
*/
public function uploadToTencentCloud( $config,$key = null) {
$secretId = $config['tencent_secretid'];
$secretKey = $config['tencent_secretkey'];
$region = $config['tencent_area']; // 例如 ap-beijing, ap-guangzhou
$bucket = $config['tencent_bucket'];
$data = $this->request->file();
$info = $data['file']->getInfo();
$parts = explode('.', $info['name']);
$extension = end($parts);
$filename=hash('md5', uniqid()).mt_rand(1,99).'.'.$extensi

最低0.47元/天 解锁文章
2097

被折叠的 条评论
为什么被折叠?



