七牛云 rs.php 没有,设置了callbackUrl,七牛只是在客户端上打印了json格式的key和hash,居然没有按照设置跳转回来..怎么弄?...

文件是上传成功了,但是就停了,咩有按照设置的callbackUrl跳转,我只是想上传之后七牛返回Location字段为我设置的URl,并且带post或get,好让我把上传文件信息插入数据库,还有callbackBody和returnBody除有什么区别?感激不尽..

bVlbWo

bVlbWP

flag和表单代码如下:(隐藏了accesskey还有srcretkey)

print_r($_POST);

$client = new QiniuClient($accessKey,$secretKey);

$flag = array('scope'=>'help', 'saveKey'=> 'kdfsufes6asdawes4ks.zip','callbackUrl '=> '"http://6.ncic.sinaapp.com/"', 'callbackBody' => '"name": $(fname),

"size": $(fsize),

"w": $(imageInfo.width),

"h": $(imageInfo.height),

"hash": $(etag),');

//print_r($client);

//print $token;print $access_token;

?>

enctype="multipart/form-data">

include的内容

class QiniuClient

{

const UP_HOST = 'http://up.qiniu.com';

const RS_HOST = 'http://rs.qbox.me';

const RSF_HOST = 'http://rsf.qbox.me';

public $accessKey;

public $secretKey;

function __construct($accessKey='',$secretKey='')

{

$this->accessKey = $accessKey;

$this->secretKey = $secretKey;

}

public function uploadFile($filePath,$bucket,$key=null)

{

$uploadToken = $this->uploadToken(array('scope' => $bucket));

$data = array();

$data['file'] = "@$filePath";

$data['token'] = $uploadToken;

if($key) $data['key'] = $key;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, self::UP_HOST);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$result = curl_exec($ch);

curl_close($ch);

return $result;

}

public function upload($content,$bucket,$key=null)

{

$filePath = tempnam(sys_get_temp_dir(), 'UPLOAD');

file_put_contents($filePath, $content);

$result = $this->uploadFile($filePath,$bucket,$key);

unlink($filePath);

return $result;

}

public function uploadRemote($url,$bucket,$key=null)

{

$filePath = tempnam(sys_get_temp_dir(), 'UPLOAD');

copy($url,$filePath);

$result = $this->uploadFile($filePath,$bucket,$key);

unlink($filePath);

return $result;

}

public function stat($bucket,$key)

{

$encodedEntryURI = self::urlsafe_base64_encode("{$bucket}:{$key}");

$url = "/stat/{$encodedEntryURI}";

return $this->fileHandle($url);

}

public function move($bucket,$key,$bucket2,$key2=false)

{

if(!$key2) {

$key2 = $bucket2;

$bucket2 = $bucket;

}

$encodedEntryURISrc = self::urlsafe_base64_encode("{$bucket}:{$key}");

$encodedEntryURIDest = self::urlsafe_base64_encode("{$bucket2}:{$key2}");

$url = "/move/{$encodedEntryURISrc}/{$encodedEntryURIDest}";

return $this->fileHandle($url);

}

public function copy($bucket,$key,$bucket2,$key2=false)

{

if(!$key2) {

$key2 = $bucket2;

$bucket2 = $bucket;

}

$encodedEntryURISrc = self::urlsafe_base64_encode("{$bucket}:{$key}");

$encodedEntryURIDest = self::urlsafe_base64_encode("{$bucket2}:{$key2}");

$url = "/copy/{$encodedEntryURISrc}/{$encodedEntryURIDest}";

return $this->fileHandle($url);

}

public function delete($bucket,$key)

{

$encodedEntryURI = self::urlsafe_base64_encode("{$bucket}:{$key}");

$url = "/delete/{$encodedEntryURI}";

return $this->fileHandle($url);

}

// $operator = stat|move|copy|delete

// $client->batch('stat',array('square:test/test5.txt','square:test/test13.png'));

public function batch($operator,$files)

{

$data = '';

foreach ($files as $file) {

if(!is_array($file)) {

$encodedEntryURI = self::urlsafe_base64_encode($file);

$data.="op=/{$operator}/{$encodedEntryURI}&";

}else{

$encodedEntryURI = self::urlsafe_base64_encode($file[0]);

$encodedEntryURIDest = self::urlsafe_base64_encode($file[1]);

$data.="op=/{$operator}/{$encodedEntryURI}/{$encodedEntryURIDest}&";

}

}

return $this->fileHandle('/batch',$data);

}

public function listFiles($bucket,$limit='',$prefix='',$marker='')

{

$params = array_filter(compact('bucket','limit','prefix','marker'));

$url = self::RSF_HOST.'/list?'.http_build_query($params);

return $this->fileHandle($url);

}

public function fileHandle($url,$data=array())

{

if(strpos($url, 'http://')!==0) $url = self::RS_HOST.$url;

if(is_array($data)) $accessToken = $this->accessToken($url);

else $accessToken = $this->accessToken($url,$data);

$ch = curl_init();

curl_setopt($ch, CURLOPT_HTTPHEADER, array(

'Authorization: QBox '.$accessToken,

));

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POST, true);

// If $data is an array, the Content-Type header will be set to multipart/form-data

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

$info = curl_getinfo($ch);

curl_close($ch);

if($info['http_code']>=300)

throw new Exception($info['http_code'].': '.$result);

if($info['content_type']=='application/json')

return json_decode($result,true);

return $result;

}

public function uploadToken($flags)

{

if(!isset($flags['deadline']))

$flags['deadline'] = 3600 + time();

$encodedFlags = self::urlsafe_base64_encode(json_encode($flags));

$sign = hash_hmac('sha1', $encodedFlags, $this->secretKey, true);

$encodedSign = self::urlsafe_base64_encode($sign);

$token = $this->accessKey.':'.$encodedSign. ':' . $encodedFlags;

return $token;

}

public function accessToken($url,$body=false){

$parsed_url = parse_url($url);

$path = $parsed_url['path'];

$access = $path;

if (isset($parsed_url['query'])) {

$access .= "?" . $parsed_url['query'];

}

$access .= "\n";

if($body) $access .= $body;

$digest = hash_hmac('sha1', $access, $this->secretKey, true);

return $this->accessKey.':'.self::urlsafe_base64_encode($digest);

}

public static function urlsafe_base64_encode($str){

$find = array("+","/");

$replace = array("-", "_");

return str_replace($find, $replace, base64_encode($str));

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值