rsf_list_bucket.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Storage\BucketManager;
  5. // http://developer.qiniu.com/docs/v6/api/reference/rs/list.html#list-description
  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. $prefix = '';
  13. // 上次列举返回的位置标记,作为本次列举的起点信息。
  14. $marker = '';
  15. // 本次列举的条目数
  16. $limit = 200;
  17. $delimiter = '/';
  18. // 列举文件
  19. do {
  20. list($ret, $err) = $bucketManager->listFiles($bucket, $prefix, $marker, $limit, $delimiter);
  21. if ($err !== null) {
  22. echo "\n====> list file err: \n";
  23. var_dump($err);
  24. } else {
  25. $marker = null;
  26. if (array_key_exists('marker', $ret)) {
  27. $marker = $ret['marker'];
  28. }
  29. echo "Marker: $marker\n";
  30. echo "\nList Items====>\n";
  31. //var_dump($ret['items']);
  32. print('items count:' . count($ret['items']) . "\n");
  33. if (array_key_exists('commonPrefixes', $ret)) {
  34. print_r($ret['commonPrefixes']);
  35. }
  36. }
  37. } while (!empty($marker));