Ingen beskrivning

put_referAntiLeech.php 1.0KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Config;
  5. use Qiniu\Storage\BucketManager;
  6. // 控制台获取密钥:https://portal.qiniu.com/user/key
  7. $accessKey = getenv('QINIU_ACCESS_KEY');
  8. $secretKey = getenv('QINIU_SECRET_KEY');
  9. $auth = new Auth($accessKey, $secretKey);
  10. $config = new Config();
  11. $bucketManager = new BucketManager($auth, $config);
  12. // 存储空间 - 设置 referer 防盗链
  13. // 参考文档:https://developer.qiniu.com/kodo/manual/6093/set-the-hotlinking-prevention
  14. $bucket = getenv('QINIU_TEST_BUCKET');
  15. $mode = 1; // 关闭Referer(使用此选项将会忽略以下参数并将恢复默认值):0,设置Referer白名单:1,表示设置Referer黑名单:2
  16. $norefer = "1"; // 表示不允许空 Refer 访问:0,表示允许空 Refer 访问:1
  17. $pattern = "*.qiniu.com"; // 当前仅支持这三种格式:a.b.com,*.b.com,*
  18. list($ret, $err) = $bucketManager->putReferAntiLeech($bucket, $mode, $norefer, $pattern);
  19. if ($err != null) {
  20. var_dump($err);
  21. } else {
  22. var_dump($ret);
  23. }