sample.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. require('./include.php');
  3. use Qcloud_cos\Auth;
  4. use Qcloud_cos\Cosapi;
  5. use Qcloud_cos\CosDb;
  6. $bucketName = 'test';
  7. $srcPath = './test.log';
  8. $dstPath = '/sdk/test.log';
  9. $dstFolder = '/sdk/';
  10. Cosapi::setTimeout(180);
  11. //创建文件夹
  12. $createFolderRet = Cosapi::createFolder($bucketName, $dstFolder);
  13. var_dump($createFolderRet);
  14. //上传文件
  15. $bizAttr = "";
  16. $insertOnly = 0;
  17. $sliceSize = 3 * 1024 * 1024;
  18. $uploadRet = Cosapi::upload($bucketName, $srcPath, $dstPath,$bizAttr,$sliceSize, $insertOnly);
  19. var_dump($uploadRet);
  20. //目录列表
  21. $listnum = 20;
  22. $pattern = "eListBoth";
  23. $order = 0;
  24. $listRet = Cosapi::listFolder($bucketName, $dstFolder,$listnum,$pattern, $order);
  25. var_dump($listRet);
  26. //更新目录信息
  27. $bizAttr = "";
  28. $updateRet = Cosapi::updateFolder($bucketName, $dstFolder, $bizAttr);
  29. var_dump($updateRet);
  30. //更新文件信息
  31. $bizAttr = "";
  32. $authority = "eWPrivateRPublic";
  33. $customer_headers_array = array(
  34. 'Cache-Control' => "no",
  35. 'Content-Type' => "application/pdf",
  36. 'Content-Language' => "ch",
  37. );
  38. $updateRet = Cosapi::update($bucketName, $dstPath, $bizAttr,$authority, $customer_headers_array);
  39. var_dump($updateRet);
  40. //查询目录信息
  41. $statRet = Cosapi::statFolder($bucketName, $dstFolder);
  42. var_dump($statRet);
  43. //查询文件信息
  44. $statRet = Cosapi::stat($bucketName, $dstPath);
  45. var_dump($statRet);
  46. //删除文件
  47. $delRet = Cosapi::delFile($bucketName, $dstPath);
  48. var_dump($delRet);
  49. //删除目录
  50. $delRet = Cosapi::delFolder($bucketName, $dstFolder);
  51. var_dump($delRet);