No Description

rsf_list_bucket.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Storage\BucketManager;
  5. // 控制台获取密钥:https://portal.qiniu.com/user/key
  6. $accessKey = getenv('QINIU_ACCESS_KEY');
  7. $secretKey = getenv('QINIU_SECRET_KEY');
  8. $bucket = getenv('QINIU_TEST_BUCKET');
  9. $auth = new Auth($accessKey, $secretKey);
  10. $bucketManager = new BucketManager($auth);
  11. // 资源列举
  12. // 参考文档:https://developer.qiniu.com/kodo/api/1284/list
  13. // 要列取文件的公共前缀
  14. $prefix = '';
  15. // 上次列举返回的位置标记,作为本次列举的起点信息。
  16. $marker = '';
  17. // 本次列举的条目数,范围为 1-1000
  18. $limit = 200;
  19. $delimiter = '/';
  20. do {
  21. list($ret, $err) = $bucketManager->listFiles($bucket, $prefix, $marker, $limit, $delimiter);
  22. if ($err !== null) {
  23. echo "\n====> list file err: \n";
  24. var_dump($err);
  25. } else {
  26. $marker = null;
  27. if (array_key_exists('marker', $ret)) {
  28. $marker = $ret['marker'];
  29. }
  30. echo "Marker: $marker\n";
  31. echo "\nList Items====>\n";
  32. //var_dump($ret['items']);
  33. print('items count:' . count($ret['items']) . "\n");
  34. if (array_key_exists('commonPrefixes', $ret)) {
  35. print_r($ret['commonPrefixes']);
  36. }
  37. }
  38. } while (!empty($marker));