mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
40 lines
883 B
PHP
40 lines
883 B
PHP
<?php
|
|
require_once __DIR__ . '/../autoload.php';
|
|
|
|
// 引入鉴权类
|
|
use Qiniu\Auth;
|
|
|
|
// 引入上传类
|
|
use Qiniu\Storage\UploadManager;
|
|
|
|
// 需要填写你的 Access Key 和 Secret Key
|
|
$accessKey = 'Access_Key';
|
|
$secretKey = 'Secret_Key';
|
|
|
|
// 构建鉴权对象
|
|
$auth = new Auth($accessKey, $secretKey);
|
|
|
|
// 要上传的空间
|
|
$bucket = 'Bucket_Name';
|
|
|
|
// 生成上传 Token
|
|
$token = $auth->uploadToken($bucket);
|
|
|
|
// 要上传文件的本地路径
|
|
$filePath = './php-logo.png';
|
|
|
|
// 上传到七牛后保存的文件名
|
|
$key = 'my-php-logo.png';
|
|
|
|
// 初始化 UploadManager 对象并进行文件的上传。
|
|
$uploadMgr = new UploadManager();
|
|
|
|
// 调用 UploadManager 的 putFile 方法进行文件的上传。
|
|
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
|
|
echo "\n====> putFile result: \n";
|
|
if ($err !== null) {
|
|
var_dump($err);
|
|
} else {
|
|
var_dump($ret);
|
|
}
|