dever 4 vuotta sitten
vanhempi
commit
f15020f12e
3 muutettua tiedostoa jossa 24 lisäystä ja 15 poistoa
  1. 11 5
      lib/Store/Core.php
  2. 9 10
      lib/Store/Local.php
  3. 4 0
      src/Save.php

+ 11 - 5
lib/Store/Core.php

@@ -163,7 +163,7 @@ class Core
 	 */
 	private function check_size()
 	{
-		if (!$this->limit) {
+		if (!$this->limit && !$this->base64 && ($this->ext == '.jpg' || $this->ext == '.gif' || $this->ext == '.png')) {
 			$this->limit = getimagesize($this->data['file']['tmp_name']);
 		}
 
@@ -176,10 +176,10 @@ class Core
 			if (($size < $this->data['file']['size']) && $size > 0) {
 				$this->output['status'] = -1;
 				$this->output['message'] = '文件不能超过'.(($size/1024)/1024).'MB';
-			} elseif ($this->config['width'] > 0 && $this->config['width'] < $this->limit[0]) {
+			} elseif ($this->limit && $this->config['width'] > 0 && $this->config['width'] < $this->limit[0]) {
 				$this->output['status'] = -1;
 				$this->output['message'] = '图片宽度不能超过' . $this->config['width'] . 'px';
-			} elseif ($this->config['height'] > 0 && $this->config['height'] < $this->limit[1]) {
+			} elseif ($this->limit && $this->config['height'] > 0 && $this->config['height'] < $this->limit[1]) {
 				$this->output['status'] = -1;
 				$this->output['message'] = '图片高度不能超过' . $this->config['height'] . 'px';
 			}
@@ -198,13 +198,18 @@ class Core
 		$this->output['status'] = 1; 
 
 		if (is_string($this->data['file'])) {
-			if (strstr($this->data['file'], 'base64,') && isset($this->data['pic'])) {
+			if (strstr($this->data['file'], 'base64,')) {
 				$temp = explode('base64,', $this->data['file']);
 				$type = str_replace(array('data:', ';'), '', $temp[0]);
 				$file = str_replace(' ', '+', $temp[1]);
 				$file = str_replace('=', '', $temp[1]);
 		        $file = base64_decode($file);
-		        $name = $this->data['local'] = Dever::local($this->data['pic']);
+		        if (isset($this->data['pic'])) {
+		        	$name = $this->data['local'] = Dever::local($this->data['pic']);
+		        } else {
+		        	$name = Dever::rand(10);
+		        }
+		        
 		        $size = strlen($file);
 		        $size = number_format(($size - ($size/8)*2)/1024, 2);
 		        $this->base64 = true;
@@ -629,6 +634,7 @@ class Core
 			'audio/x-mpegurl' => 'm3u',
 			'audio/x-pn-realaudio' => 'ram',
 			'audio/x-wav' => 'wav',
+			'image/png' => 'png',
 			'image/bmp' => 'bmp',
 			'image/cis-cod' => 'cod',
 			'image/gif' => 'gif',

+ 9 - 10
lib/Store/Local.php

@@ -32,6 +32,15 @@ class Local extends Core implements Config
 				$file = Dever::load('upload/file-name', array('where_name' => $this->name, 'where_upload' => $this->data['key'], 'rand' => time()));
 			}
 
+			if ($this->base64) {
+				file_put_contents($this->output['file'], $this->data['file']['tmp_name']);
+			} elseif (!copy($this->data['file']['tmp_name'], $this->output['file'])) {
+				$this->output['status'] = -1;
+				$this->output['message'] = '文件已经存在';
+			} else {
+				//unlink($this->data['file']['tmp_name']);
+			}
+
 			if (!$this->limit && ($this->ext == '.jpg' || $this->ext == '.gif' || $this->ext == '.png')) {
 				$this->limit = getimagesize($this->output['file']);
 			}
@@ -42,20 +51,10 @@ class Local extends Core implements Config
 			
 			if (isset($file) && $file) {
 				$this->update($file['id']);
-				
 			} else {
 				$this->insert();
 			}
 
-			if ($this->base64) {
-				file_put_contents($this->output['file'], $this->data['file']['tmp_name']);
-			} elseif (!copy($this->data['file']['tmp_name'], $this->output['file'])) {
-				$this->output['status'] = -1;
-				$this->output['message'] = '文件已经存在';
-			} else {
-				//unlink($this->data['file']['tmp_name']);
-			}
-
 			@chmod($this->output['file'], 0755);
             //@system('chmod -R 777 ' . $this->output['file']);
 

+ 4 - 0
src/Save.php

@@ -46,6 +46,10 @@ class Save
 		if ($search && $search > 0) {
 			$image['search'] .= '_' . $search;
 		}
+
+		if (!$image['file'] || !$image['key']) {
+			Dever::alert('传入参数错误');
+		}
 		//file_put_contents(Dever::data() . 'upload.txt', var_export($image, true)); 
 		if ($image['file']) {