finance-pay/vendor/qiniu/php-sdk/examples/upload_with_zone.php

40 lines
1.0 KiB
PHP
Raw Normal View History

2023-11-15 12:02:33 +08:00
<?php
require_once __DIR__ . '/../autoload.php';
use Qiniu\Auth;
use Qiniu\Zone;
use Qiniu\Config;
use Qiniu\Storage\UploadManager;
// 控制台获取密钥https://portal.qiniu.com/user/key
$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$auth = new Auth($accessKey, $secretKey);
// 上传到七牛存储后文件所在的空间和文件名
$bucket = getenv('QINIU_TEST_BUCKET');
$key = 'php-logo.png';
$uptoken = $auth->uploadToken($bucket);
// 上传文件的本地路径
$filePath = './php-logo.png';
// 指定 zone 上传
// 参考文档https://developer.qiniu.com/kodo/manual/1671/region-endpoint
$zone = Zone::zonez0(); // 华东z0华北z1华南z2北美na0东南亚as0
$config = new Config($zone);
$config->useHTTPS = true;
// 指定 config
$uploadMgr = new UploadManager($config);
list($ret, $err) = $uploadMgr->putFile($uptoken, $key, $filePath);
echo "\n====> putFile result: \n";
if ($err !== null) {
var_dump($err);
} else {
var_dump($ret);
}