暫無描述

upload_with_qvmzone.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Zone;
  5. use Qiniu\Config;
  6. use Qiniu\Storage\UploadManager;
  7. // 控制台获取密钥:https://portal.qiniu.com/user/key
  8. $accessKey = getenv('QINIU_ACCESS_KEY');
  9. $secretKey = getenv('QINIU_SECRET_KEY');
  10. $auth = new Auth($accessKey, $secretKey);
  11. // 上传到七牛存储后文件所在的空间和文件名
  12. $bucket = getenv('QINIU_TEST_BUCKET');
  13. $key = 'php-logo.png';
  14. $uptoken = $auth->uploadToken($bucket);
  15. // 上传文件的本地路径
  16. $filePath = './php-logo.png';
  17. // 七牛云主机QVM和七牛对象存储KODO内网上传,目前支持华东1区域(杭州)和华北2区域(北京)的云主机可以访问同区域的对象存储服务
  18. // 参考文档:https://developer.qiniu.com/qvm/manual/4269/qvm-kodo
  19. $zone = Zone::qvmZonez0(); // 华东:z0,华北:z1
  20. $config = new Config($zone);
  21. $config->useHTTPS = true;
  22. // 指定 config
  23. $uploadMgr = new UploadManager($config);
  24. list($ret, $err) = $uploadMgr->putFile($uptoken, $key, $filePath);
  25. echo "\n====> putFile result: \n";
  26. if ($err !== null) {
  27. var_dump($err);
  28. } else {
  29. var_dump($ret);
  30. }