利用七牛的php SDK分片上传时如何处理Notify?

我的代码如下,有填写相应的Rio_PutExtra,但是进度貌似没有输出来?请问是哪里写的不对么?…

function upload($bucket, $key, $file, $type="file"){
$qiniu_key = "…AK…";
$qiniu_sec = "…SK…";
Qiniu_SetKeys($qiniu_key, $qiniu_sec);
$putPolicy = new Qiniu_RS_PutPolicy("$bucket:$key");
$upToken = $putPolicy->Token(null);

try{
    if($type == "file"){
        $progress = array();

        $putExtra = new Qiniu_Rio_PutExtra($bucket);
        $putExtra->TryTimes = 3;
        $putExtra->Progress = $progress;
        $putExtra->Notify = function ($blkIdx, $blkSize, &$progress) {
            echo ($blkIdx + " : " + $blkSize);
            var_dump($progress);
            ob_flush();
            flush();
        };
        $putExtra->NotifyErr = function ($blkIdx, $blkSize, $error) {
            echo ($blkIdx + " : " + $blkSize);
            var_dump($error);
            ob_flush();
            flush();
        };

        list($ret, $err) = Qiniu_Rio_PutFile($upToken, $key, $file, $putExtra);
    } else if($type == "text"){
        $putExtra = new Qiniu_PutExtra();
        $putExtra->MimeType = "text/html";

        list($ret, $err) = Qiniu_Put($upToken, $key, $file, $putExtra);
    }

    if ($err !== null) {
        var_dump($err);
    } else {
        var_dump($ret);
    }

} catch (Exception $e) {
    return "Qiniu failed:" . $e->getMessage();
}

    return "done!";
}

$res = upload("myBucket", "fuck.shit", "t.zip", "file");
var_dump($res);
阅读 4.1k
1 个回答

之前使用该功能的人比较少,没有实现。现在已经提了pr,请下载最新版本的phpsdk。
你的代码 "echo ($blkIdx + " : " + $blkSize);" 要改成 "echo $blkIdx . " : " . $blkSize;"?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进