Sen descrición

rs_batch_delete_after_days.php 862B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. $bucket = getenv('QINIU_TEST_BUCKET');
  10. $auth = new Auth($accessKey, $secretKey);
  11. $config = new Config();
  12. $bucketManager = new BucketManager($auth, $config);
  13. // 批量修改文件生命周期,每次最多不能超过 1000 个
  14. $keys = array(
  15. 'qiniu.mp4',
  16. 'qiniu.png',
  17. 'qiniu.jpg'
  18. );
  19. $keyDayPairs = array();
  20. // day=0表示永久存储
  21. foreach ($keys as $key) {
  22. $keyDayPairs[$key] = 0;
  23. }
  24. $ops = $bucketManager->buildBatchDeleteAfterDays($bucket, $keyDayPairs);
  25. list($ret, $err) = $bucketManager->batch($ops);
  26. if ($err != null) {
  27. var_dump($err);
  28. } else {
  29. var_dump($ret);
  30. }