mirror of https://gitee.com/karson/fastadmin.git
上传又拍云时可扩展参数
parent
ed231a0365
commit
2bc34f575f
|
|
@ -117,26 +117,13 @@ class Backend extends Controller
|
|||
$this->view->engine->layout('layout/' . $this->layout);
|
||||
}
|
||||
|
||||
// 上传参数配置配置
|
||||
$uploadcfg = Configvalue::upload();
|
||||
|
||||
$upload = [
|
||||
'uploadurl' => $uploadcfg['uploadurl'],
|
||||
'cdnurl' => $uploadcfg['cdnurl'],
|
||||
'multipart' => [
|
||||
'policy' => $uploadcfg['policy'],
|
||||
'signature' => $uploadcfg['signature']
|
||||
],
|
||||
'maxsize' => $uploadcfg['maxsize'],
|
||||
'mimetype' => $uploadcfg['mimetype'],
|
||||
];
|
||||
|
||||
// 语言检测
|
||||
$lang = Lang::detect();
|
||||
|
||||
// 配置信息
|
||||
$config = [
|
||||
'site' => Config::get("site"),
|
||||
'upload' => $upload,
|
||||
'upload' => Configvalue::upload(),
|
||||
'modulename' => $modulename,
|
||||
'controllername' => $controllername,
|
||||
'actionname' => $actionname,
|
||||
|
|
|
|||
|
|
@ -21,34 +21,53 @@ class Configvalue extends Model
|
|||
/**
|
||||
* 加载上传配置
|
||||
*
|
||||
* @param string $savekey 保存路径 例:/{year}/{mon}/{day}/{filemd5}{.suffix}
|
||||
* @param mixed $mimetype 上传类型 例:image/*,application/zip
|
||||
* @param int $maxsize 上传文件大小 例:10mb
|
||||
* @param array $params 扩展参数,常用字段savekey,mimetype,maxsize,ext-param,notify-url,return-url<br>
|
||||
* 更多字段可参考http://docs.upyun.com/api/form_api/#_2
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function upload($savekey = '', $mimetype = '', $maxsize = '')
|
||||
public static function upload($params = [])
|
||||
{
|
||||
$uploadcfg = Config::get('upload');
|
||||
$uploadcfg = $uploadcfg ? $uploadcfg : [];
|
||||
$bucket = isset($uploadcfg['bucket']) ? $uploadcfg['bucket'] : '';
|
||||
$savekey = $savekey ? $savekey : (isset($uploadcfg['savekey']) ? $uploadcfg['savekey'] : '');
|
||||
$expiration = time() + (isset($uploadcfg['expire']) ? $uploadcfg['expire'] : 0);
|
||||
$options = [
|
||||
'bucket' => $bucket,
|
||||
'save-key' => $savekey,
|
||||
'expiration' => $expiration
|
||||
$uploadcfg = array_merge($uploadcfg, $params);
|
||||
$uploadcfg['bucket'] = isset($uploadcfg['bucket']) ? $uploadcfg['bucket'] : '';
|
||||
$savekey = isset($uploadcfg['savekey']) ? $uploadcfg['savekey'] : '';
|
||||
$uploadcfg['save-key'] = isset($uploadcfg['save-key']) ? $uploadcfg['save-key'] : $savekey;
|
||||
$expiration = time() + (isset($uploadcfg['expire']) ? $uploadcfg['expire'] : 600);
|
||||
$uploadcfg['expiration'] = isset($uploadcfg['expiration']) ? $uploadcfg['expiration'] : $expiration;
|
||||
$notifyurl = isset($uploadcfg['notifyurl']) ? $uploadcfg['notifyurl'] : '';
|
||||
$returnurl = isset($uploadcfg['returnurl']) ? $uploadcfg['returnurl'] : '';
|
||||
if ($notifyurl)
|
||||
$uploadcfg['notify-url'] = $notifyurl;
|
||||
else
|
||||
unset($uploadcfg['notify-url']);
|
||||
if ($returnurl)
|
||||
$uploadcfg['return-url'] = $returnurl;
|
||||
else
|
||||
unset($uploadcfg['return-url']);
|
||||
|
||||
//设置允许的附加字段
|
||||
$allowfields = [
|
||||
'bucket', 'save-key', 'expiration', 'date', 'content-md5', 'notify-url', 'return-url', 'content-secret', 'content-type', 'allow-file-type', 'content-length-range',
|
||||
'image-width-range', 'image-height-range', 'x-gmkerl-thumb', 'x-gmkerl-type', 'apps', 'b64encoded', 'ext-param'
|
||||
];
|
||||
$policy = base64_encode(json_encode($options));
|
||||
$params = array_intersect_key($uploadcfg, array_flip($allowfields));
|
||||
$policy = base64_encode(json_encode($params));
|
||||
$signature = md5($policy . '&' . (isset($uploadcfg['formkey']) ? $uploadcfg['formkey'] : ''));
|
||||
$multipart = [
|
||||
'policy' => $policy,
|
||||
'signature' => $signature,
|
||||
];
|
||||
|
||||
$multipart = array_merge($multipart, $params);
|
||||
return [
|
||||
'cdnurl' => isset($uploadcfg['cdnurl']) ? $uploadcfg['cdnurl'] : '',
|
||||
'uploadurl' => isset($uploadcfg['uploadurl']) ? $uploadcfg['uploadurl'] : url('ajax/upload'),
|
||||
'bucket' => isset($uploadcfg['bucket']) ? $uploadcfg['bucket'] : '',
|
||||
'maxsize' => $maxsize ? $maxsize : (isset($uploadcfg['maxsize']) ? $uploadcfg['maxsize'] : ''),
|
||||
'mimetype' => $mimetype ? $mimetype : (isset($uploadcfg['mimetype']) ? $uploadcfg['mimetype'] : ''),
|
||||
'policy' => $policy,
|
||||
'signature' => $signature,
|
||||
'bucket' => $uploadcfg['bucket'],
|
||||
'maxsize' => isset($uploadcfg['maxsize']) ? $uploadcfg['maxsize'] : '',
|
||||
'mimetype' => isset($uploadcfg['mimetype']) ? $uploadcfg['mimetype'] : '',
|
||||
'multipart' => $multipart,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue