rsf.php 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. require_once("http.php");
  3. define('Qiniu_RSF_EOF', 'EOF');
  4. /**
  5. * 1. 首次请求 marker = ""
  6. * 2. 无论 err 值如何,均应该先看 items 是否有内容
  7. * 3. 如果后续没有更多数据,err 返回 EOF,markerOut 返回 ""(但不通过该特征来判断是否结束)
  8. */
  9. function Qiniu_RSF_ListPrefix(
  10. $self, $bucket, $prefix = '', $marker = '', $limit = 0) // => ($items, $markerOut, $err)
  11. {
  12. global $QINIU_RSF_HOST;
  13. $query = array('bucket' => $bucket);
  14. if (!empty($prefix)) {
  15. $query['prefix'] = $prefix;
  16. }
  17. if (!empty($marker)) {
  18. $query['marker'] = $marker;
  19. }
  20. if (!empty($limit)) {
  21. $query['limit'] = $limit;
  22. }
  23. $url = $QINIU_RSF_HOST . '/list?' . http_build_query($query);
  24. list($ret, $err) = Qiniu_Client_Call($self, $url);
  25. if ($err !== null) {
  26. return array(null, '', $err);
  27. }
  28. $items = $ret['items'];
  29. if (empty($ret['marker'])) {
  30. $markerOut = '';
  31. $err = Qiniu_RSF_EOF;
  32. } else {
  33. $markerOut = $ret['marker'];
  34. }
  35. return array($items, $markerOut, $err);
  36. }