dever 6 年之前
父節點
當前提交
3d2986b6a1
共有 5 個文件被更改,包括 72 次插入13 次删除
  1. 1 1
      database/file.php
  2. 9 3
      src/Manage.php
  3. 60 6
      src/Qiniu.php
  4. 1 1
      src/Store/Handle.php
  5. 1 2
      src/View.php

+ 1 - 1
database/file.php

@@ -253,7 +253,7 @@ return array
 		(
 			'where' => array
 			(
-				'name' => 'is_string',
+				'name' => 'yes',
 				'upload' => 'yes',
 			),
 			'type' => 'one',

+ 9 - 3
src/Manage.php

@@ -51,9 +51,15 @@ class Manage
         $table = array();
 
         $html = '';
-        $config = Dever::db('upload/upload')->one($info['key']);
-        $link = Dever::upload('{uploadRes}' . $info['file']);
-        if (strstr($info['file'], '.png') || strstr($info['file'], '.jpg')) {
+        $config = Dever::db('upload/upload')->one($info['upload']);
+        if ($config['yun'] && $config['save_type'] > 1) {
+            $yun = Dever::db('upload/yun')->one($config['yun']);
+            $link = $yun['host'] . $info['file'];
+        } else {
+            $link = Dever::upload('{uploadRes}' . $info['file']);
+        }
+        
+        if (strstr($info['file'], '.png') || strstr($info['file'], '.jpg') || strstr($info['file'], '.gif')) {
             $html = '<img src="'.$link.'" width="100" />';
         }
 

+ 60 - 6
src/Qiniu.php

@@ -16,15 +16,69 @@ class Qiniu
 		$body = file_get_contents('php://input');  
 		file_put_contents(Dever::data() . "test.txt",$body);
 		$body = json_decode($body, true);
-		$fname = $body['filename'];
-		$fkey = $body['fkey'];
-		$filesize = $body['filesize'];
+		$file = $body['filename'];
+		$key = $body['key'];
+		$size = $body['filesize'];
 		$width = $body['width'];
 		$height = $body['height'];
-		$arr=array("date"=>"test");   
-		echo json_encode($arr);   
+
+        $config = Dever::db('upload/upload')->one($key);
+
+        if ($config) {
+            $this->initFile($key, $file, $file, $width, $height, $size);
+        }
+		return 'ok'; 
 	}
 
+    private function initFile($key, $file, $source, $width = false, $height = false, $size = false)
+    {
+        $temp = explode('/', $file);
+        $name = $temp[count($temp) - 1];
+        $temp = explode('.', $name);
+        $name = $temp[0];
+        $ext = $temp[count($temp) - 1];
+
+        $info = Dever::load('upload/file-name', array('where_name' => $name, 'where_upload' => $key));
+
+        $data['name'] = $name;
+        $data['file'] = $file;
+        $data['key'] = md5($file);
+        $data['ext'] = $ext;
+
+        if ($width) {
+            $data['width'] = $width;
+        }
+
+        if ($height) {
+            $data['height'] = $height;
+        }
+
+        if ($size) {
+            $data['size'] = $size;
+        }
+        $data['upload'] = $key;
+        if ($info) {
+            $data['where_id'] = $info['id'];
+            Dever::db('upload/file')->update($data);
+        } else {
+            $data['source_name'] = $source;
+            Dever::db('upload/file')->insert($data);
+        }
+    }
+
+    public function addFile()
+    {
+        $file = Dever::input('file');
+        $key = Dever::input('key');
+        $source = Dever::input('source');
+
+        $config = Dever::db('upload/upload')->one($key);
+
+        if ($config) {
+            $this->initFile($key, $file, $source);
+        }
+    }
+
     public function token()
     {
         $key = Dever::input('key');
@@ -42,7 +96,7 @@ class Qiniu
 
         $policy = array(
             'callbackUrl' => Dever::url('qiniu.callback', 'upload'),
-            'callbackBody' => 'filename=$(fname)&fkey=$(key)&filesize=$(fsize)&width=$(imageInfo.width)&height=$(imageInfo.height)'
+            'callbackBody' => 'filename=$(fname)&key=$(key)&filesize=$(fsize)&width=$(imageInfo.width)&height=$(imageInfo.height)'
         );
 
         // 生成上传Token

+ 1 - 1
src/Store/Handle.php

@@ -38,7 +38,7 @@ class Handle
     }
 
     # 获取文件名
-    public function getName()
+    public function name()
     {
         return $this->get('getName');
     }

+ 1 - 2
src/View.php

@@ -21,8 +21,7 @@ class View
         if ($image['file']) {
             $handle = new Handle($image);
 
-            $this->output = $handle->copy();
-            unset($this->output['file']);
+            $this->output = $handle->name();
         }
     }