logistics_sy/vendor/qiniu/php-sdk/examples/upload_with_zone.php

40 lines
1.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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);
}