rs_fetch.php 876B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Storage\BucketManager;
  5. $accessKey = getenv('QINIU_ACCESS_KEY');
  6. $secretKey = getenv('QINIU_SECRET_KEY');
  7. $bucket = getenv('QINIU_TEST_BUCKET');
  8. $auth = new Auth($accessKey, $secretKey);
  9. $bucketManager = new BucketManager($auth);
  10. $url = 'http://devtools.qiniu.com/qiniu.png';
  11. $key = time() . '.png';
  12. // 指定抓取的文件保存名称
  13. list($ret, $err) = $bucketManager->fetch($url, $bucket, $key);
  14. echo "=====> fetch $url to bucket: $bucket key: $key\n";
  15. if ($err !== null) {
  16. var_dump($err);
  17. } else {
  18. print_r($ret);
  19. }
  20. // 不指定key时,以文件内容的hash作为文件名
  21. $key = null;
  22. list($ret, $err) = $bucketManager->fetch($url, $bucket, $key);
  23. echo "=====> fetch $url to bucket: $bucket key: $(etag)\n";
  24. if ($err !== null) {
  25. var_dump($err);
  26. } else {
  27. print_r($ret);
  28. }