Sen descrición

bucket_lifecycleRule.php 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Config;
  5. use Qiniu\Storage\BucketManager;
  6. // 控制台获取密钥:https://portal.qiniu.com/user/key
  7. $accessKey = getenv('QINIU_ACCESS_KEY');
  8. $secretKey = getenv('QINIU_SECRET_KEY');
  9. $auth = new Auth($accessKey, $secretKey);
  10. $config = new Config();
  11. $bucketManager = new BucketManager($auth, $config);
  12. // 存储空间 - 新增生命周期规则
  13. // 参考文档:https://developer.qiniu.com/kodo/manual/3699/life-cycle-management
  14. $bucket = 'xxxx'; // 存储空间名称
  15. $name = 'demo'; // 生命周期规则名称
  16. $prefix = 'test'; // 规则策略中的前缀
  17. $delete_after_days = 80; // 用户新创建的文件将在该设定时间之后自动删除
  18. $to_line_after_days = 70; // 用户新创建的文件将在该设定的时间之后自动转为低频存储
  19. list($ret, $err) = $bucketManager->bucketLifecycleRule(
  20. $bucket,
  21. $name,
  22. $prefix,
  23. $delete_after_days,
  24. $to_line_after_days
  25. );
  26. if ($err != null) {
  27. var_dump($err);
  28. } else {
  29. var_dump($ret);
  30. }