get.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. require_once("../ucloud/proxy.php");
  3. //存储空间名
  4. $bucket = "your bucket";
  5. //上传至存储空间后的文件名称(请不要和API公私钥混淆)
  6. $key = "your key";
  7. function curl_file_get_contents($durl){
  8. $ch = curl_init();
  9. curl_setopt($ch, CURLOPT_URL, $durl);
  10. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回
  11. curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回
  12. $r = curl_exec($ch);
  13. curl_close($ch);
  14. return $r;
  15. }
  16. /*
  17. * 访问公有Bucket的例子
  18. */
  19. $url = UCloud_MakePublicUrl($bucket, $key);
  20. echo "download url(public): ", $url . "\n";
  21. /*
  22. * 访问私有Bucket的例子
  23. */
  24. $url = UCloud_MakePrivateUrl($bucket, $key);
  25. echo "download url(private): ", $url . "\n";
  26. /*
  27. * 访问包含过期时间的私有Bucket例子
  28. */
  29. $curtime = time();
  30. $curtime += 60; // 有效期60秒
  31. $url = UCloud_MakePrivateUrl($bucket, $key, $curtime);
  32. $content = curl_file_get_contents($url);
  33. echo "download file with expires: ", $url . "\n";