人人商城

sample.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. require('./include.php');
  3. use qcloudcos\Cosapi;
  4. $bucket = 'testbucket';
  5. $src = './111.txt';
  6. $dst = '/testfolder/111.txt';
  7. $folder = '/testfolder';
  8. Cosapi::setTimeout(180);
  9. // 设置COS所在的区域,对应关系如下:
  10. // 华南 -> gz
  11. // 华中 -> sh
  12. // 华北 -> tj
  13. Cosapi::setRegion('gz');
  14. // Create folder in bucket.
  15. $ret = Cosapi::createFolder($bucket, $folder);
  16. var_dump($ret);
  17. // Upload file into bucket.
  18. $ret = Cosapi::upload($bucket, $src, $dst);
  19. var_dump($ret);
  20. // List folder.
  21. $ret = Cosapi::listFolder($bucket, $folder);
  22. var_dump($ret);
  23. // Update folder information.
  24. $bizAttr = "";
  25. $ret = Cosapi::updateFolder($bucket, $folder, $bizAttr);
  26. var_dump($ret);
  27. // Update file information.
  28. $bizAttr = '';
  29. $authority = 'eWPrivateRPublic';
  30. $customerHeaders = array(
  31. 'Cache-Control' => 'no',
  32. 'Content-Type' => 'application/pdf',
  33. 'Content-Language' => 'ch',
  34. );
  35. $ret = Cosapi::update($bucket, $dst, $bizAttr,$authority, $customerHeaders);
  36. var_dump($ret);
  37. // Stat folder.
  38. $ret = Cosapi::statFolder($bucket, $folder);
  39. var_dump($ret);
  40. // Stat file.
  41. $ret = Cosapi::stat($bucket, $dst);
  42. var_dump($ret);
  43. // Copy file.
  44. $ret = Cosapi::copyFile($bucket, $dst, $dst . '_copy');
  45. var_dump($ret);
  46. // Move file.
  47. $ret = Cosapi::moveFile($bucket, $dst, $dst . '_move');
  48. var_dump($ret);
  49. // Delete file.
  50. $ret = Cosapi::delFile($bucket, $dst . '_copy');
  51. var_dump($ret);
  52. $ret = Cosapi::delFile($bucket, $dst . '_move');
  53. var_dump($ret);
  54. // Delete folder.
  55. $ret = Cosapi::delFolder($bucket, $folder);
  56. var_dump($ret);