Няма описание

rs_fetch.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/1263/fetch
  13. // 需要抓取的文件 URL
  14. $url = 'http://devtools.qiniu.com/qiniu.png';
  15. //---------------------------------------- demo1 ----------------------------------------
  16. // 指定抓取的文件保存到七牛云空间中的名称
  17. $key = time() . '.png';
  18. list($ret, $err) = $bucketManager->fetch($url, $bucket, $key);
  19. echo "=====> fetch $url to bucket: $bucket key: $key\n";
  20. if ($err !== null) {
  21. var_dump($err);
  22. } else {
  23. print_r($ret);
  24. }
  25. //---------------------------------------- demo2 ----------------------------------------
  26. // 不指定 key 时,以文件内容的 hash 作为文件名
  27. $key = null;
  28. list($ret, $err) = $bucketManager->fetch($url, $bucket, $key);
  29. echo "=====> fetch $url to bucket: $bucket key: $(etag)\n";
  30. if ($err !== null) {
  31. var_dump($err);
  32. } else {
  33. print_r($ret);
  34. }