|
@@ -21,34 +21,53 @@ class Configvalue extends Model |
|
@@ -21,34 +21,53 @@ class Configvalue extends Model |
21
|
/**
|
21
|
/**
|
22
|
* 加载上传配置
|
22
|
* 加载上传配置
|
23
|
*
|
23
|
*
|
24
|
- * @param string $savekey 保存路径 例:/{year}/{mon}/{day}/{filemd5}{.suffix}
|
|
|
25
|
- * @param mixed $mimetype 上传类型 例:image/*,application/zip
|
|
|
26
|
- * @param int $maxsize 上传文件大小 例:10mb
|
24
|
+ * @param array $params 扩展参数,常用字段savekey,mimetype,maxsize,ext-param,notify-url,return-url<br>
|
|
|
25
|
+ * 更多字段可参考http://docs.upyun.com/api/form_api/#_2
|
27
|
*
|
26
|
*
|
28
|
* @return array
|
27
|
* @return array
|
29
|
*/
|
28
|
*/
|
30
|
- public static function upload($savekey = '', $mimetype = '', $maxsize = '')
|
29
|
+ public static function upload($params = [])
|
31
|
{
|
30
|
{
|
32
|
$uploadcfg = Config::get('upload');
|
31
|
$uploadcfg = Config::get('upload');
|
33
|
$uploadcfg = $uploadcfg ? $uploadcfg : [];
|
32
|
$uploadcfg = $uploadcfg ? $uploadcfg : [];
|
34
|
- $bucket = isset($uploadcfg['bucket']) ? $uploadcfg['bucket'] : '';
|
|
|
35
|
- $savekey = $savekey ? $savekey : (isset($uploadcfg['savekey']) ? $uploadcfg['savekey'] : '');
|
|
|
36
|
- $expiration = time() + (isset($uploadcfg['expire']) ? $uploadcfg['expire'] : 0);
|
|
|
37
|
- $options = [
|
|
|
38
|
- 'bucket' => $bucket,
|
|
|
39
|
- 'save-key' => $savekey,
|
|
|
40
|
- 'expiration' => $expiration
|
33
|
+ $uploadcfg = array_merge($uploadcfg, $params);
|
|
|
34
|
+ $uploadcfg['bucket'] = isset($uploadcfg['bucket']) ? $uploadcfg['bucket'] : '';
|
|
|
35
|
+ $savekey = isset($uploadcfg['savekey']) ? $uploadcfg['savekey'] : '';
|
|
|
36
|
+ $uploadcfg['save-key'] = isset($uploadcfg['save-key']) ? $uploadcfg['save-key'] : $savekey;
|
|
|
37
|
+ $expiration = time() + (isset($uploadcfg['expire']) ? $uploadcfg['expire'] : 600);
|
|
|
38
|
+ $uploadcfg['expiration'] = isset($uploadcfg['expiration']) ? $uploadcfg['expiration'] : $expiration;
|
|
|
39
|
+ $notifyurl = isset($uploadcfg['notifyurl']) ? $uploadcfg['notifyurl'] : '';
|
|
|
40
|
+ $returnurl = isset($uploadcfg['returnurl']) ? $uploadcfg['returnurl'] : '';
|
|
|
41
|
+ if ($notifyurl)
|
|
|
42
|
+ $uploadcfg['notify-url'] = $notifyurl;
|
|
|
43
|
+ else
|
|
|
44
|
+ unset($uploadcfg['notify-url']);
|
|
|
45
|
+ if ($returnurl)
|
|
|
46
|
+ $uploadcfg['return-url'] = $returnurl;
|
|
|
47
|
+ else
|
|
|
48
|
+ unset($uploadcfg['return-url']);
|
|
|
49
|
+
|
|
|
50
|
+ //设置允许的附加字段
|
|
|
51
|
+ $allowfields = [
|
|
|
52
|
+ 'bucket', 'save-key', 'expiration', 'date', 'content-md5', 'notify-url', 'return-url', 'content-secret', 'content-type', 'allow-file-type', 'content-length-range',
|
|
|
53
|
+ 'image-width-range', 'image-height-range', 'x-gmkerl-thumb', 'x-gmkerl-type', 'apps', 'b64encoded', 'ext-param'
|
41
|
];
|
54
|
];
|
42
|
- $policy = base64_encode(json_encode($options));
|
55
|
+ $params = array_intersect_key($uploadcfg, array_flip($allowfields));
|
|
|
56
|
+ $policy = base64_encode(json_encode($params));
|
43
|
$signature = md5($policy . '&' . (isset($uploadcfg['formkey']) ? $uploadcfg['formkey'] : ''));
|
57
|
$signature = md5($policy . '&' . (isset($uploadcfg['formkey']) ? $uploadcfg['formkey'] : ''));
|
|
|
58
|
+ $multipart = [
|
|
|
59
|
+ 'policy' => $policy,
|
|
|
60
|
+ 'signature' => $signature,
|
|
|
61
|
+ ];
|
|
|
62
|
+
|
|
|
63
|
+ $multipart = array_merge($multipart, $params);
|
44
|
return [
|
64
|
return [
|
45
|
'cdnurl' => isset($uploadcfg['cdnurl']) ? $uploadcfg['cdnurl'] : '',
|
65
|
'cdnurl' => isset($uploadcfg['cdnurl']) ? $uploadcfg['cdnurl'] : '',
|
46
|
'uploadurl' => isset($uploadcfg['uploadurl']) ? $uploadcfg['uploadurl'] : url('ajax/upload'),
|
66
|
'uploadurl' => isset($uploadcfg['uploadurl']) ? $uploadcfg['uploadurl'] : url('ajax/upload'),
|
47
|
- 'bucket' => isset($uploadcfg['bucket']) ? $uploadcfg['bucket'] : '',
|
|
|
48
|
- 'maxsize' => $maxsize ? $maxsize : (isset($uploadcfg['maxsize']) ? $uploadcfg['maxsize'] : ''),
|
|
|
49
|
- 'mimetype' => $mimetype ? $mimetype : (isset($uploadcfg['mimetype']) ? $uploadcfg['mimetype'] : ''),
|
|
|
50
|
- 'policy' => $policy,
|
|
|
51
|
- 'signature' => $signature,
|
67
|
+ 'bucket' => $uploadcfg['bucket'],
|
|
|
68
|
+ 'maxsize' => isset($uploadcfg['maxsize']) ? $uploadcfg['maxsize'] : '',
|
|
|
69
|
+ 'mimetype' => isset($uploadcfg['mimetype']) ? $uploadcfg['mimetype'] : '',
|
|
|
70
|
+ 'multipart' => $multipart,
|
52
|
];
|
71
|
];
|
53
|
}
|
72
|
}
|
54
|
|
73
|
|