mupload.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. require_once('../ucloud/proxy.php');
  3. //存储空间名
  4. $bucket = 'your bucket';
  5. //上传至存储空间后的文件名称(请不要和API公私钥混淆)
  6. $key = 'your key';
  7. //待上传文件的本地路径
  8. $file = 'local file path';
  9. //初始化分片上传,获取本地上传的uploadId和分片大小
  10. list($data, $err) = UCloud_MInit($bucket, $key);
  11. if ($err)
  12. {
  13. echo "error: " . $err->ErrMsg . "\n";
  14. echo "code: " . $err->Code . "\n";
  15. exit;
  16. }
  17. $uploadId = $data['UploadId'];
  18. $blkSize = $data['BlkSize'];
  19. echo "UploadId: " . $uploadId . "\n";
  20. echo "BlkSize: " . $blkSize . "\n";
  21. //数据上传
  22. list($etagList, $err) = UCloud_MUpload($bucket, $key, $file, $uploadId, $blkSize);
  23. if ($err) {
  24. echo "error: " . $err->ErrMsg . "\n";
  25. echo "code: " . $err->Code . "\n";
  26. exit;
  27. }
  28. //完成上传
  29. list($data, $err) = UCloud_MFinish($bucket, $key, $uploadId, $etagList);
  30. if ($err) {
  31. echo "error: " . $err->ErrMsg . "\n";
  32. echo "code: " . $err->Code . "\n";
  33. exit;
  34. }
  35. echo "Etag: " . $data['ETag'] . "\n";
  36. echo "FileSize: " . $data['FileSize'] . "\n";