当前位置:网站首页>七牛云上传图片
七牛云上传图片
2022-06-22 12:42:00 【大得369】
安装
composer require qiniu/php-sdk
引入类
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
上传
$cfg = [
'access' => 'AccessKey',
'secret' => 'SecretKey',
'bucket' => '空间名称',
'domain' => 'https://images.your_domain.com'
];
$auth = new Auth($cfg['access'], $cfg['secret']);
// 创建一个过期时间为1小时的临时上传令牌
$token = $auth->uploadToken($cfg['bucket'], null, 3600);
$filePath = "./illustration.png";
$uploadMgr = new UploadManager();
list($ret, $err) = $uploadMgr->putFile($token, null, $filePath);
if($err !== null) {
$this->err = $err;
} else {
echo $cfg['domain'] . '/' . $ret['key'];
}
$cfg = [
'access' => '',
'secret' => '',
'bucket' => 'dadeyy',
'domain' => ''
];
$auth = new Auth($cfg['access'], $cfg['secret']);
// 创建一个过期时间为1小时的临时上传令牌
$token = $auth->uploadToken($cfg['bucket'], null, 3600);
$filePath = EASYSWOOLE_ROOT.'/public/beij/wx.png';
$path = 'public/beij/wx.png';
$uploadMgr = new UploadManager();
list($ret, $err) = $uploadMgr->putFile($token, $path, $filePath);
if($err !== null) {
$this->jsonData(200,$err,'上传成功');
} else {
$this->jsonData(200,$cfg['domain'] . '/' . $ret['key'],'上传成功');
}边栏推荐
- 448. Find All Numbers Disappeared in an Array
- 数据库 就业咨询系统求各位帮下忙
- After several years of writing at CSDN, I published "the first book". Thank you!
- Stephencovey's tips for efficient work for young people
- 190. Reverse Bits
- 241. Different Ways to Add Parentheses
- VCIP2021:利用解码信息进行超分辨率
- 谈谈人生风控
- Problème de sous - séquence / substrat leetcode
- Acwing week 52
猜你喜欢

BSN发展联盟理事长单志广:DDC可为中国元宇宙产业发展提供底层支撑
Redis+Caffeine两级缓存的实现

leetcode 1579. Ensure that the graph can be completely traversed

leetcode-二分法

openGauss数据库源码解析系列文章—— 密态等值查询技术详解

VCIP2021:利用解码信息进行超分辨率

Sword finger offer II 114 Alien dictionary

LDA study notes

leetcode-区间dp

Instanceinforeplicator class of Eureka (service registration auxiliary class)
随机推荐
Problème de sous - séquence / substrat leetcode
SQL functions -- converting a one to many relationship to a one to one relationship
Leetcode dichotomy
Redis password modification, startup, view and other operations
Common writing methods and excellent examples of acknowledgments in graduation thesis writing
openGauss内核分析之查询重写
leetcode-区间dp
leetcode 1130. Minimum cost spanning tree of leaf value
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology
In June, China database industry analysis report was released! Smart wind, train storage and regeneration
155. Min Stack
Uninstall MySQL 8
Interaction between awk language and Oracle database for nearly half a year
Acwing week 52
Eureka的InstanceInfoReplicator类(服务注册辅助类)
Leetcode math problems
Leetcode union search set
Which securities company is good for retail investors to open an account? Is it safe to open a mobile account?
定金预售的规则思路详解