Browse Source

fix #623 图片上传到远程后,支持在本地保留一份

magicblack 3 years ago
parent
commit
9f9e4194ec

+ 8 - 0
application/admin/view/system/configupload.html

@@ -138,6 +138,14 @@
                         </select>
                     </div>
                 </div>
+                <div class="layui-form-item">
+                    <label class="layui-form-label">{:lang('admin/system/configupload/keep_local')}:</label>
+                    <div class="layui-input-inline">
+                        <input type="radio" name="upload[keep_local]" value="0" title="{:lang('close')}" {if condition="$config['upload']['keep_local'] neq 1"}checked {/if}>
+                        <input type="radio" name="upload[keep_local]" value="1" title="{:lang('open')}" {if condition="$config['upload']['keep_local'] eq 1"}checked {/if}>
+                    </div>
+                    <div class="layui-form-mid layui-word-aux">{:lang('admin/system/configupload/keep_local_tip')}</div>
+                </div>
 
                 <div class="layui-form-item upload_mode mode_remote" {if condition="$config['upload']['mode'] neq 'remote'"}style="display:none;" {/if}>
                     <label class="layui-form-label">{:lang('admin/system/configupload/remoteurl')}:</label>

+ 6 - 1
application/common/extend/upload/Alibaba.php

@@ -5,6 +5,11 @@ class Alibaba
 {
     public $name = '阿里巴巴云存储';
     public $ver = '1.0';
+    private $config = [];
+
+    public function __construct($config = []) {
+        $this->config = $config;
+    }
 
     public function submit($file_path)
     {
@@ -45,7 +50,7 @@ class Alibaba
 
         if($json['code']=='0'){
             $file_path = $json['url'];
-            @unlink($filePath);
+            empty($this->config['keep_local']) && @unlink($filePath);
         }
 
         return $file_path;

+ 6 - 1
application/common/extend/upload/Ftp.php

@@ -7,6 +7,11 @@ class Ftp
 {
     public $name = 'FTP存储';
     public $ver = '1.0';
+    private $config = [];
+
+    public function __construct($config = []) {
+        $this->config = $config;
+    }
 
     public function submit($file_path)
     {
@@ -22,7 +27,7 @@ class Ftp
         $ftp->connect();
         $a = $ftp->put(ROOT_PATH. $file_path, $file_path);
         $filePath = ROOT_PATH . $file_path;
-        @unlink($filePath);
+        empty($this->config['keep_local']) && @unlink($filePath);
         return $GLOBALS['config']['upload']['api']['ftp']['url'] . '/' . $file_path;
     }
 }

+ 6 - 1
application/common/extend/upload/Qiniu.php

@@ -8,6 +8,11 @@ class Qiniu
 {
     public $name = '七牛云存储';
     public $ver = '1.0';
+    private $config = [];
+
+    public function __construct($config = []) {
+        $this->config = $config;
+    }
 
     public function submit($file_path)
     {
@@ -24,7 +29,7 @@ class Qiniu
         $filePath = ROOT_PATH . $file_path;
         $uploadMgr = new UploadManager();
         $a = $uploadMgr->putFile($token, $file_path, $filePath);
-        @unlink($filePath);
+        empty($this->config['keep_local']) && @unlink($filePath);
         return $GLOBALS['config']['upload']['api']['qiniu']['url'] . '/' . $file_path;
     }
 }

+ 6 - 1
application/common/extend/upload/Uomg.php

@@ -5,6 +5,11 @@ class Uomg
 {
     public $name = '优启梦云存储';
     public $ver = '1.0';
+    private $config = [];
+
+    public function __construct($config = []) {
+        $this->config = $config;
+    }
 
     public function submit($file_path)
     {
@@ -31,7 +36,7 @@ class Uomg
         $json = @json_decode($html,true);
         if($json['code']=='1'){
             $file_path = $json['imgurl'];
-            @unlink($filePath);
+            empty($this->config['keep_local']) && @unlink($filePath);
         }
 
         return $file_path;

+ 6 - 1
application/common/extend/upload/Upyun.php

@@ -8,6 +8,11 @@ class Upyun
 {
     public $name = '又拍云存储';
     public $ver = '1.0';
+    private $config = [];
+
+    public function __construct($config = []) {
+        $this->config = $config;
+    }
 
     public function submit($file_path)
     {
@@ -22,7 +27,7 @@ class Upyun
         $a = $client->write($file_path, $_file);
         $filePath = ROOT_PATH . $file_path;
         unset($_file);
-        @unlink($filePath);
+        empty($this->config['keep_local']) && @unlink($filePath);
         return $GLOBALS['config']['upload']['api']['upyun']['url'] . '/' . $file_path;
     }
 }

+ 5 - 0
application/common/extend/upload/Weibo.php

@@ -7,6 +7,11 @@ class Weibo
 {
     public $name = '新浪图床';
     public $ver = '1.0';
+    private $config = [];
+
+    public function __construct($config = []) {
+        $this->config = $config;
+    }
 
     public function submit($file_path)
     {

+ 1 - 1
application/common/model/Upload.php

@@ -27,7 +27,7 @@ class Upload extends Base {
         if(!in_array($config['mode'],['local','remote'])){
             $cp = 'app\\common\\extend\\upload\\' . ucfirst($config['mode']);
             if (class_exists($cp)) {
-                $c = new $cp;
+                $c = new $cp($config);
                 $file_path = $c->submit($file_path);
             }
         }

+ 2 - 0
application/lang/zh-cn.php

@@ -1314,6 +1314,8 @@ https://www.baidu.com/123.jpg
     'admin/system/configupload/img_key_tip'=>'需要处理防盗链的域名或关键字多个请用|连接',
     'admin/system/configupload/img_api'=>'反盗链接口',
     'admin/system/configupload/img_api_tip'=>'处理防盗链图片的接口地址',
+    'admin/system/configupload/keep_local'=>'保留本地',
+    'admin/system/configupload/keep_local_tip'=>'如果选择上传到远程,上传完成后,本地也将保留一份',
 
     'admin/system/configsms/title'=>'短信发送配置',
     'admin/system/configsms/tip'=>'提示信息:<br>

+ 2 - 0
application/lang/zh-tw.php

@@ -1314,6 +1314,8 @@ https://www.baidu.com/123.jpg
     'admin/system/configupload/img_key_tip'=>'需要處理防盜鏈的域名或關鍵字多個請用|連接',
     'admin/system/configupload/img_api'=>'反盜鏈接口',
     'admin/system/configupload/img_api_tip'=>'處理防盜鏈圖片的接口地址',
+    'admin/system/configupload/keep_local'=>'保留本地',
+    'admin/system/configupload/keep_local_tip'=>'如果選擇上傳到遠程,上傳完成後,本地也將保留一份',
 
     'admin/system/configsms/title'=>'短信發送配置',
     'admin/system/configsms/tip'=>'提示信息:<br>