我的代码如下,有填写相应的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);
之前使用该功能的人比较少,没有实现。现在已经提了pr,请下载最新版本的phpsdk。
你的代码 "echo ($blkIdx + " : " + $blkSize);" 要改成 "echo $blkIdx . " : " . $blkSize;"?