qiniuUpload( )七牛上传函数

/**
* @param string $mid 公众号标识
* @param string $file 上传文件物理路径
* @param string $key 保护七牛中的文件名
* @return array
*/
function qiniuUpload($mid='',$file='',$key=''){
if(!$mid){
return ['code'=>1,'msg'=>'公众号标识mid不能为空'];
}else{
$st=getSetting($mid,'cloud');
if(!isset($st['qiniu']) && empty($st['qiniu'])){
return ['code'=>1,'msg'=>'请先配置七牛云存储参数'];
}else{
\think\Loader::import('QiniuSdk.Qiniu.autoload', EXTEND_PATH, '.php');

$client =Qiniu\Qiniu::create(array(
'access_key' => $st['qiniu']['accessKey'],
'secret_key' => $st['qiniu']['secretKey'],
'bucket' => $st['qiniu']['bucke'],
'domain' => $st['qiniu']['domain']
));
$result=$client->uploadFile($file,$key);
$result=json_decode(json_encode($result),true);
if(isset($result['response']['code']) && $result['response']['code'] !='200'){
return ['code'=>1,'msg'=>$result['error']];
}else{
return $res = [
'code' => 0,
'data' => [
'src' => $result['data']['url']
]
];
}
}
}

}

0 个评论

要回复文章请先登录注册