upload_and_pfop.php 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Storage\UploadManager;
  5. $accessKey = getenv('QINIU_ACCESS_KEY');
  6. $secretKey = getenv('QINIU_SECRET_KEY');
  7. $bucket = getenv('QINIU_TEST_BUCKET');
  8. $auth = new Auth($accessKey, $secretKey);
  9. // 在七牛保存的文件名
  10. $key = 'php-logo.png';
  11. $uploadMgr = new UploadManager();
  12. $pfop = "imageMogr2/rotate/90|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":php-logo-rotate.png");
  13. //转码完成后通知到你的业务服务器。(公网可以访问,并相应200 OK)
  14. $notifyUrl = 'http://notify.fake.com';
  15. //独立的转码队列:https://portal.qiniu.com/mps/pipeline
  16. $pipeline = 'sdktest';
  17. $policy = array(
  18. 'persistentOps' => $pfop,
  19. 'persistentNotifyUrl' => $notifyUrl,
  20. 'persistentPipeline' => $pipeline
  21. );
  22. $token = $auth->uploadToken($bucket, null, 3600, $policy);
  23. list($ret, $err) = $uploadMgr->putFile($token, null, $key);
  24. echo "\n====> putFile result: \n";
  25. if ($err !== null) {
  26. var_dump($err);
  27. } else {
  28. var_dump($ret);
  29. }