rs_batch_delete_after_days.php 724 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use \Qiniu\Auth;
  4. $accessKey = getenv('QINIU_ACCESS_KEY');
  5. $secretKey = getenv('QINIU_SECRET_KEY');
  6. $bucket = getenv('QINIU_TEST_BUCKET');
  7. $auth = new Auth($accessKey, $secretKey);
  8. $config = new \Qiniu\Config();
  9. $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
  10. //每次最多不能超过1000个
  11. $keys = array(
  12. 'qiniu.mp4',
  13. 'qiniu.png',
  14. 'qiniu.jpg'
  15. );
  16. $keyDayPairs = array();
  17. //day=0表示永久存储
  18. foreach ($keys as $key) {
  19. $keyDayPairs[$key] = 0;
  20. }
  21. $ops = $bucketManager->buildBatchDeleteAfterDays($bucket, $keyDayPairs);
  22. list($ret, $err) = $bucketManager->batch($ops);
  23. if ($err) {
  24. print_r($err);
  25. } else {
  26. print_r($ret);
  27. }