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);
|
$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();
|
$lang = Lang::detect();
|
||||||
|
|
||||||
// 配置信息
|
// 配置信息
|
||||||
$config = [
|
$config = [
|
||||||
'site' => Config::get("site"),
|
'site' => Config::get("site"),
|
||||||
'upload' => $upload,
|
'upload' => Configvalue::upload(),
|
||||||
'modulename' => $modulename,
|
'modulename' => $modulename,
|
||||||
'controllername' => $controllername,
|
'controllername' => $controllername,
|
||||||
'actionname' => $actionname,
|
'actionname' => $actionname,
|
||||||
|
|
|
||||||
|
|
@ -21,34 +21,53 @@ class Configvalue extends Model
|
||||||
/**
|
/**
|
||||||
* 加载上传配置
|
* 加载上传配置
|
||||||
*
|
*
|
||||||
* @param string $savekey 保存路径 例:/{year}/{mon}/{day}/{filemd5}{.suffix}
|
* @param array $params 扩展参数,常用字段savekey,mimetype,maxsize,ext-param,notify-url,return-url<br>
|
||||||
* @param mixed $mimetype 上传类型 例:image/*,application/zip
|
* 更多字段可参考http://docs.upyun.com/api/form_api/#_2
|
||||||
* @param int $maxsize 上传文件大小 例:10mb
|
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function upload($savekey = '', $mimetype = '', $maxsize = '')
|
public static function upload($params = [])
|
||||||
{
|
{
|
||||||
$uploadcfg = Config::get('upload');
|
$uploadcfg = Config::get('upload');
|
||||||
$uploadcfg = $uploadcfg ? $uploadcfg : [];
|
$uploadcfg = $uploadcfg ? $uploadcfg : [];
|
||||||
$bucket = isset($uploadcfg['bucket']) ? $uploadcfg['bucket'] : '';
|
$uploadcfg = array_merge($uploadcfg, $params);
|
||||||
$savekey = $savekey ? $savekey : (isset($uploadcfg['savekey']) ? $uploadcfg['savekey'] : '');
|
$uploadcfg['bucket'] = isset($uploadcfg['bucket']) ? $uploadcfg['bucket'] : '';
|
||||||
$expiration = time() + (isset($uploadcfg['expire']) ? $uploadcfg['expire'] : 0);
|
$savekey = isset($uploadcfg['savekey']) ? $uploadcfg['savekey'] : '';
|
||||||
$options = [
|
$uploadcfg['save-key'] = isset($uploadcfg['save-key']) ? $uploadcfg['save-key'] : $savekey;
|
||||||
'bucket' => $bucket,
|
$expiration = time() + (isset($uploadcfg['expire']) ? $uploadcfg['expire'] : 600);
|
||||||
'save-key' => $savekey,
|
$uploadcfg['expiration'] = isset($uploadcfg['expiration']) ? $uploadcfg['expiration'] : $expiration;
|
||||||
'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'] : ''));
|
$signature = md5($policy . '&' . (isset($uploadcfg['formkey']) ? $uploadcfg['formkey'] : ''));
|
||||||
|
$multipart = [
|
||||||
|
'policy' => $policy,
|
||||||
|
'signature' => $signature,
|
||||||
|
];
|
||||||
|
|
||||||
|
$multipart = array_merge($multipart, $params);
|
||||||
return [
|
return [
|
||||||
'cdnurl' => isset($uploadcfg['cdnurl']) ? $uploadcfg['cdnurl'] : '',
|
'cdnurl' => isset($uploadcfg['cdnurl']) ? $uploadcfg['cdnurl'] : '',
|
||||||
'uploadurl' => isset($uploadcfg['uploadurl']) ? $uploadcfg['uploadurl'] : url('ajax/upload'),
|
'uploadurl' => isset($uploadcfg['uploadurl']) ? $uploadcfg['uploadurl'] : url('ajax/upload'),
|
||||||
'bucket' => isset($uploadcfg['bucket']) ? $uploadcfg['bucket'] : '',
|
'bucket' => $uploadcfg['bucket'],
|
||||||
'maxsize' => $maxsize ? $maxsize : (isset($uploadcfg['maxsize']) ? $uploadcfg['maxsize'] : ''),
|
'maxsize' => isset($uploadcfg['maxsize']) ? $uploadcfg['maxsize'] : '',
|
||||||
'mimetype' => $mimetype ? $mimetype : (isset($uploadcfg['mimetype']) ? $uploadcfg['mimetype'] : ''),
|
'mimetype' => isset($uploadcfg['mimetype']) ? $uploadcfg['mimetype'] : '',
|
||||||
'policy' => $policy,
|
'multipart' => $multipart,
|
||||||
'signature' => $signature,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue