作者:手机用户2502889621 | 来源:互联网 | 2023-09-05 14:40
上传文件到七牛最简单的方式就是使用七牛官方最新的SDK安装PHPSDKcomposerrequireqiniuphp-sdk上传文件到七牛useQiniu\Auth;use
上传文件到七牛最简单的方式就是使用七牛官方最新的SDK
安装PHP SDK
composer require qiniu/php-sdk
上传文件到七牛
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
$cfg = [
'access' => 'YOUR_ACCESS_KEY',
'secret' => 'YOUR_SECRET_KEY',
'bucket' => 'YOUR_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'];
}
搞定!
原文地址:https://segmentfault.com/a/1190000015753617