pfop_mkzip.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Processing\PersistentFop;
  5. // 去我们的portal 后台来获取AK, SK
  6. $accessKey = getenv('QINIU_ACCESS_KEY');
  7. $secretKey = getenv('QINIU_SECRET_KEY');
  8. $bucket = getenv('QINIU_TEST_BUCKET');
  9. $key = 'qiniu.png';
  10. $auth = new Auth($accessKey, $secretKey);
  11. // 异步任务的队列, 去后台新建: https://portal.qiniu.com/mps/pipeline
  12. $pipeline = 'sdktest';
  13. $pfop = new PersistentFop($auth, null);
  14. // 进行zip压缩的url
  15. $url1 = 'http://phpsdk.qiniudn.com/php-logo.png';
  16. $url2 = 'http://phpsdk.qiniudn.com/1.png';
  17. //压缩后的key
  18. $zipKey = 'test.zip';
  19. $fops = 'mkzip/2/url/' . \Qiniu\base64_urlSafeEncode($url1);
  20. $fops .= '/url/' . \Qiniu\base64_urlSafeEncode($url2);
  21. $fops .= '|saveas/' . \Qiniu\base64_urlSafeEncode("$bucket:$zipKey");
  22. $notify_url = null;
  23. $force = false;
  24. list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notify_url, $force);
  25. echo "\n====> pfop mkzip result: \n";
  26. if ($err != null) {
  27. var_dump($err);
  28. } else {
  29. echo "PersistentFop Id: $id\n";
  30. $res = "http://api.qiniu.com/status/get/prefop?id=$id";
  31. echo "Processing result: $res";
  32. }