dever преди 3 години
родител
ревизия
3e3218e042
променени са 3 файла, в които са добавени 37 реда и са изтрити 8 реда
  1. 17 4
      lib/Store/Core.php
  2. 11 1
      lib/Store/Qiniu.php
  3. 9 3
      src/Save.php

+ 17 - 4
lib/Store/Core.php

@@ -226,13 +226,17 @@ class Core
 		        //$size = number_format(($size - ($size/8)*2)/1024, 2);
 		        $size = round(($size - ($size/8)*2)/1024, 2);
 		        $this->base64 = true;
+			} elseif (strstr($this->data['file'], 'content,')) {
+				$file = str_replace('content,', '', $this->data['file']);
+				$this->data['cropper'] = 1;
 			} else {
 				$name = urldecode($this->data['file']);
 			}
 
 			$this->data['file'] = array();
-			if (((isset($this->data['cropper']) && !$this->yun) || !isset($this->data['cropper'])) && strstr($name, 'http') && !$this->yun) {
+			if (((isset($this->data['cropper']) && !$this->yun) || (!isset($this->data['cropper'])) && strstr($name, 'http') && !$this->yun)) {
 				$this->base64 = false;
+
 				$this->root();
 				//header('Content-type: text/json; charset=utf-8');
 				$path = Dever::path($this->base, 'tmp/');
@@ -248,7 +252,11 @@ class Core
 					$this->ext = '.' . pathinfo($filename, PATHINFO_EXTENSION);
 				}
 				
-				$this->data['file']['name'] = 'Tmp' . sha1($filename);
+				if (isset($this->data['name']) && $this->data['name']) {
+					$this->data['file']['name'] = 'Tmp' . sha1($this->data['name']);
+				} else {
+					$this->data['file']['name'] = 'Tmp' . sha1($filename);
+				}
 				$this->data['file']['tmp_name'] = $path . $this->data['file']['name'];
 
 				if (!is_file($this->data['file']['tmp_name'])) {
@@ -261,7 +269,7 @@ class Core
 						$file = Dever::curl($name);
 					}
 					
-					if (stristr($file, 'webp')) {
+					if ($this->ext != '.mp4' && stristr($file, 'webp')) {
 						# 将webp图片转成jpg
 						$this->ext = '.jpg';
 					}
@@ -270,6 +278,7 @@ class Core
 						$this->output['message'] = '错误的文件来源';
 						return $this->output;
 					}
+
 					$state = file_put_contents($this->data['file']['tmp_name'], $file);
 					if (!$state) {
 						$this->delete();
@@ -470,7 +479,11 @@ class Core
 
 		if (!$this->path) {
 			$date = explode('-', date("Y-m-d"));
-			$this->path = $this->config['id'] . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
+			if (isset($this->data['id']) && $this->data['id']) {
+				$this->path = $this->config['id'] . '/' . Dever::pathId($this->data['id']);
+			} else {
+				$this->path = $this->config['id'] . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
+			}
 		}
 
 		return $this;

+ 11 - 1
lib/Store/Qiniu.php

@@ -28,7 +28,7 @@ class Qiniu extends Core implements Config
             if (!$this->limit) {
                 $data = Dever::curl($this->output['url'] . '?imageInfo');
                 if ($data) {
-                    $data = json_decode($data, true);
+                    $data = Dever::json_decode($data);
                     if (isset($data['width'])) {
                         $this->limit = array($data['width'], $data['height']);
                         $this->size = $data['size'];
@@ -39,7 +39,17 @@ class Qiniu extends Core implements Config
                             $method->delete($this->file);
                             return $this->output;
                         }
+                    } else {
+                        $this->output['status'] = -1;
+                        $this->output['message'] = '上传失败';
+                        $method->delete($this->file);
+                        return $this->output;
                     }
+                } else {
+                    $this->output['status'] = -1;
+                    $this->output['message'] = '上传失败';
+                    $method->delete($this->file);
+                    return $this->output;
                 }
             }
 

+ 9 - 3
src/Save.php

@@ -71,7 +71,7 @@ class Save
 		}
 	}
 
-	public function copy($file = false, $key = 1, $state = false, $search = '', $ext = false)
+	public function copy($file = false, $key = 1, $state = false, $search = '', $ext = false, $name = false, $id = false)
 	{
 		if ($search == 'undefined') {
 			$search = '';
@@ -86,6 +86,12 @@ class Save
 			if ($ext) {
 				$image['ext'] = $ext;
 			}
+			if ($name) {
+				$image['name'] = $name;
+			}
+			if ($id) {
+				$image['id'] = $id;
+			}
 			
 			$handle = new Handle($image);
 
@@ -95,12 +101,12 @@ class Save
 		}
 	}
 
-	public function copys($file, $key = 1, $search = '')
+	public function copys($file, $key = 1, $search = '', $ext = false, $name = false)
 	{
 		$file = urldecode($file);
 		$file = explode(',', $file);
 		foreach ($file as $v) {
-			$copy = $this->copy($v, $key, true, $search);
+			$copy = $this->copy($v, $key, true, $search, $ext, $name);
 			if (isset($copy['url'])) {
 				$result[] = $copy['url'];
 			} else {