Ver código fonte

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

Karson 4 anos atrás
pai
commit
926e16bde6

+ 2 - 2
application/admin/view/common/header.html

@@ -65,7 +65,7 @@
                 <!-- 账号信息下拉框 -->
                 <li class="dropdown user user-menu">
                     <a href="#" class="dropdown-toggle" data-toggle="dropdown">
-                        <img src="{$admin.avatar|cdnurl|htmlentities}" class="user-image" alt="{$admin.nickname|htmlentities}">
+                        <img src="{$admin.avatar|cdnurl|htmlentities}" class="user-image" alt="">
                         <span class="hidden-xs">{$admin.nickname|htmlentities}</span>
                     </a>
                     <ul class="dropdown-menu">
@@ -112,4 +112,4 @@
         </ul>
     </div>
     {/if}
-</nav>
+</nav>

+ 0 - 6
application/admin/view/general/attachment/add.html

@@ -11,9 +11,6 @@
         <label for="c-third" class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">
             <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>
-            {if config('upload.chunking')}
-            <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>
-            {/if}
         </div>
     </div>
     {/if}
@@ -29,9 +26,6 @@
         <label for="c-local" class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">
             <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>
-            {if config('upload.chunking')}
-            <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>
-            {/if}
         </div>
     </div>
 

+ 8 - 0
application/common/library/Upload.php

@@ -174,6 +174,14 @@ class Upload
         var_dump($array);
     }
 
+    /**
+     * 合并分片文件
+     * @param string $chunkid
+     * @param int    $chunkcount
+     * @param string $filename
+     * @return attachment|\think\Model
+     * @throws UploadException
+     */
     public function merge($chunkid, $chunkcount, $filename)
     {
         $filePath = $this->chunkDir . DS . $chunkid;

+ 2 - 0
application/common/model/Config.php

@@ -171,6 +171,8 @@ class Config extends Model
             'bucket'    => 'local',
             'maxsize'   => $uploadcfg['maxsize'],
             'mimetype'  => $uploadcfg['mimetype'],
+            'chunking'  => $uploadcfg['chunking'],
+            'chunksize' => $uploadcfg['chunksize'],
             'multipart' => [],
             'multiple'  => $uploadcfg['multiple'],
         ];

+ 4 - 0
application/extra/upload.php

@@ -30,4 +30,8 @@ return [
      * 是否支持分片上传
      */
     'chunking'  => false,
+    /**
+     * 默认分片大小
+     */
+    'chunksize' => 2097152,
 ];

+ 5 - 0
public/assets/js/require-upload.js

@@ -141,6 +141,9 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
                         //上传URL
                         url = url ? url : Config.upload.uploadurl;
                         url = Fast.api.fixurl(url);
+                        var chunking = Config.upload.chunking || false,
+                            chunkSize = Config.upload.chunksize || 2097152;
+
                         //最大可上传文件大小
                         maxsize = typeof maxsize !== "undefined" ? maxsize : Config.upload.maxsize;
                         //文件类型
@@ -190,6 +193,8 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
                                 }
                                 return params;
                             },
+                            chunking: chunking,
+                            chunkSize: chunkSize,
                             maxFilesize: maxFilesize,
                             acceptedFiles: mimetype,
                             maxFiles: (maxcount && parseInt(maxcount) > 1 ? maxcount : (multiple ? null : 1)),