dever 4 years ago
parent
commit
03a0babb40
2 changed files with 37 additions and 29 deletions
  1. 4 3
      lib/Store/Handle.php
  2. 33 26
      src/View.php

+ 4 - 3
lib/Store/Handle.php

@@ -21,12 +21,13 @@ class Handle
         if ($this->save_type >= 2) {
             $yun = Dever::db('upload/yun')->one($yun);
             if ($yun['type'] == 2) {
-                $yun = 'Upload\Lib\Store\Qiniu';
+                $class = 'Upload\Lib\Store\Qiniu';
             } elseif ($yun['type'] == 1) {
-                $yun = 'Upload\Lib\Store\Oss';
+                $class = 'Upload\Lib\Store\Oss';
             }
+            $data['host'] = $yun['host'];
             
-            $this->yun = new $yun($data);
+            $this->yun = new $class($data);
         }
 
         if ($this->save_type <= 3) {

+ 33 - 26
src/View.php

@@ -309,37 +309,44 @@ class View
 
         if ($id > 0) {
             $host = Dever::config('host')->uploadRes;
-            $root = Dever::data() . 'upload/';
-            $source = Dever::pic($source);
-            $dest = str_replace(array('{uploadRes}', $host), $root, $file);
-            $path = str_replace(array('{uploadRes}', $host), '', $file);
-            if (strstr($source, $host)) {
-                
-                $source = $root . str_replace($host, '', $source);
+            $dest = $file;
+            $path = '';
+            $handle = true;
+            if (strstr($file, '{uploadRes}') || strstr($file, $host)) {
+                # 本地的
+                $root = Dever::data() . 'upload/';
+                $source = Dever::pic($source);
+                $dest = str_replace(array('{uploadRes}', $host), $root, $file);
+                $path = str_replace($root, '', $dest);
+                if (strstr($source, $host)) {
+                    
+                    $source = $root . str_replace($host, '', $source);
+
+                    if (!is_file($source)) {
+                        $source = $array[0];
+                    }
+                }
 
-                if (!is_file($source)) {
-                    $source = $array[0];
+                if ($type == 'wp') {
+                    $temp = explode('.', $dest);
+                    $dest = $temp[0] . '.webp';
+                    $file = str_replace($root, $host, $dest);
                 }
-            }
 
-            if ($type == 'wp') {
-                $temp = explode('.', $dest);
-                $dest = $temp[0] . '.webp';
-                $file = str_replace($root, $host, $dest);
+                if (is_file($dest)) {
+                    $file = $dest;
+                    $handle = false;
+                }
             }
 
-            if (is_file($dest)) {
-                $file = $dest;
-            } else {
-                if (!strstr($dest, 'http://')) {
-                    $temp = explode('/', $path);
-                    $key = $temp[0];
-                    $image['file']  = false;
-                    $image['key']   = $key;
-                    $handle = new Handle($image);
-                    $method = 'handle_' . $type;
-                    $file = $handle->$method($id, $source, $dest, $path);
-                }
+            if ($handle) {
+                $temp = explode('/', $path);
+                $key = $temp[0];
+                $image['file']  = false;
+                $image['key']   = $key;
+                $handle = new Handle($image);
+                $method = 'handle_' . $type;
+                $file = $handle->$method($id, $source, $dest, $path);
             }
         }