putObject.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. require dirname(__FILE__) . '/../vendor/autoload.php';
  3. $secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
  4. $secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
  5. $region = "ap-beijing"; //设置一个默认的存储桶地域
  6. $cosClient = new Qcloud\Cos\Client(
  7. array(
  8. 'region' => $region,
  9. 'schema' => 'https', //协议头部,默认为http
  10. 'credentials'=> array(
  11. 'secretId' => $secretId ,
  12. 'secretKey' => $secretKey)));
  13. $local_path = "/data/exampleobject";
  14. try {
  15. $result = $cosClient->putObject(array(
  16. 'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
  17. 'Key' => 'exampleobject',
  18. 'Body' => fopen($local_path, 'rb'),
  19. /*
  20. 'CacheControl' => 'string',
  21. 'ContentDisposition' => 'string',
  22. 'ContentEncoding' => 'string',
  23. 'ContentLanguage' => 'string',
  24. 'ContentLength' => integer,
  25. 'ContentType' => 'string',
  26. 'Expires' => 'string',
  27. 'Metadata' => array(
  28. 'string' => 'string',
  29. ),
  30. 'StorageClass' => 'string'
  31. */
  32. ));
  33. // 请求成功
  34. print_r($result);
  35. } catch (\Exception $e) {
  36. // 请求失败
  37. echo($e);
  38. }