作者 Karson

优化分片上传配置开关和分片大小

@@ -65,7 +65,7 @@ @@ -65,7 +65,7 @@
65 <!-- 账号信息下拉框 --> 65 <!-- 账号信息下拉框 -->
66 <li class="dropdown user user-menu"> 66 <li class="dropdown user user-menu">
67 <a href="#" class="dropdown-toggle" data-toggle="dropdown"> 67 <a href="#" class="dropdown-toggle" data-toggle="dropdown">
68 - <img src="{$admin.avatar|cdnurl|htmlentities}" class="user-image" alt="{$admin.nickname|htmlentities}"> 68 + <img src="{$admin.avatar|cdnurl|htmlentities}" class="user-image" alt="">
69 <span class="hidden-xs">{$admin.nickname|htmlentities}</span> 69 <span class="hidden-xs">{$admin.nickname|htmlentities}</span>
70 </a> 70 </a>
71 <ul class="dropdown-menu"> 71 <ul class="dropdown-menu">
@@ -112,4 +112,4 @@ @@ -112,4 +112,4 @@
112 </ul> 112 </ul>
113 </div> 113 </div>
114 {/if} 114 {/if}
115 -</nav>  
  115 +</nav>
@@ -11,9 +11,6 @@ @@ -11,9 +11,6 @@
11 <label for="c-third" class="control-label col-xs-12 col-sm-2"></label> 11 <label for="c-third" class="control-label col-xs-12 col-sm-2"></label>
12 <div class="col-xs-12 col-sm-8"> 12 <div class="col-xs-12 col-sm-8">
13 <button type="button" id="faupload-third" class="btn btn-danger faupload" data-multiple="true" data-input-id="c-third" ><i class="fa fa-upload"></i> {:__("Upload to third")}</button> 13 <button type="button" id="faupload-third" class="btn btn-danger faupload" data-multiple="true" data-input-id="c-third" ><i class="fa fa-upload"></i> {:__("Upload to third")}</button>
14 - {if config('upload.chunking')}  
15 - <button type="button" id="faupload-third-chunk" class="btn btn-danger faupload" data-chunking="true" data-multiple="true" data-input-id="c-third" ><i class="fa fa-upload"></i> {:__("Upload to third by chunk")}</button>  
16 - {/if}  
17 </div> 14 </div>
18 </div> 15 </div>
19 {/if} 16 {/if}
@@ -29,9 +26,6 @@ @@ -29,9 +26,6 @@
29 <label for="c-local" class="control-label col-xs-12 col-sm-2"></label> 26 <label for="c-local" class="control-label col-xs-12 col-sm-2"></label>
30 <div class="col-xs-12 col-sm-8"> 27 <div class="col-xs-12 col-sm-8">
31 <button type="button" id="faupload-local" class="btn btn-primary faupload" data-input-id="c-local" data-url="{:url('ajax/upload')}"><i class="fa fa-upload"></i> {:__("Upload to local")}</button> 28 <button type="button" id="faupload-local" class="btn btn-primary faupload" data-input-id="c-local" data-url="{:url('ajax/upload')}"><i class="fa fa-upload"></i> {:__("Upload to local")}</button>
32 - {if config('upload.chunking')}  
33 - <button type="button" id="faupload-local-chunking" class="btn btn-primary faupload" data-chunking="true" data-input-id="c-local" data-url="{:url('ajax/upload')}"><i class="fa fa-upload"></i> {:__("Upload to local by chunk")}</button>  
34 - {/if}  
35 </div> 29 </div>
36 </div> 30 </div>
37 31
@@ -174,6 +174,14 @@ class Upload @@ -174,6 +174,14 @@ class Upload
174 var_dump($array); 174 var_dump($array);
175 } 175 }
176 176
  177 + /**
  178 + * 合并分片文件
  179 + * @param string $chunkid
  180 + * @param int $chunkcount
  181 + * @param string $filename
  182 + * @return attachment|\think\Model
  183 + * @throws UploadException
  184 + */
177 public function merge($chunkid, $chunkcount, $filename) 185 public function merge($chunkid, $chunkcount, $filename)
178 { 186 {
179 $filePath = $this->chunkDir . DS . $chunkid; 187 $filePath = $this->chunkDir . DS . $chunkid;
@@ -171,6 +171,8 @@ class Config extends Model @@ -171,6 +171,8 @@ class Config extends Model
171 'bucket' => 'local', 171 'bucket' => 'local',
172 'maxsize' => $uploadcfg['maxsize'], 172 'maxsize' => $uploadcfg['maxsize'],
173 'mimetype' => $uploadcfg['mimetype'], 173 'mimetype' => $uploadcfg['mimetype'],
  174 + 'chunking' => $uploadcfg['chunking'],
  175 + 'chunksize' => $uploadcfg['chunksize'],
174 'multipart' => [], 176 'multipart' => [],
175 'multiple' => $uploadcfg['multiple'], 177 'multiple' => $uploadcfg['multiple'],
176 ]; 178 ];
@@ -30,4 +30,8 @@ return [ @@ -30,4 +30,8 @@ return [
30 * 是否支持分片上传 30 * 是否支持分片上传
31 */ 31 */
32 'chunking' => false, 32 'chunking' => false,
  33 + /**
  34 + * 默认分片大小
  35 + */
  36 + 'chunksize' => 2097152,
33 ]; 37 ];
@@ -141,6 +141,9 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined, @@ -141,6 +141,9 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
141 //上传URL 141 //上传URL
142 url = url ? url : Config.upload.uploadurl; 142 url = url ? url : Config.upload.uploadurl;
143 url = Fast.api.fixurl(url); 143 url = Fast.api.fixurl(url);
  144 + var chunking = Config.upload.chunking || false,
  145 + chunkSize = Config.upload.chunksize || 2097152;
  146 +
144 //最大可上传文件大小 147 //最大可上传文件大小
145 maxsize = typeof maxsize !== "undefined" ? maxsize : Config.upload.maxsize; 148 maxsize = typeof maxsize !== "undefined" ? maxsize : Config.upload.maxsize;
146 //文件类型 149 //文件类型
@@ -190,6 +193,8 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined, @@ -190,6 +193,8 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
190 } 193 }
191 return params; 194 return params;
192 }, 195 },
  196 + chunking: chunking,
  197 + chunkSize: chunkSize,
193 maxFilesize: maxFilesize, 198 maxFilesize: maxFilesize,
194 acceptedFiles: mimetype, 199 acceptedFiles: mimetype,
195 maxFiles: (maxcount && parseInt(maxcount) > 1 ? maxcount : (multiple ? null : 1)), 200 maxFiles: (maxcount && parseInt(maxcount) > 1 ? maxcount : (multiple ? null : 1)),