dever 5 years ago
parent
commit
04b1718de8
6 changed files with 100 additions and 33 deletions
  1. 7 0
      callback/qiniu.php
  2. 56 0
      src/Qiniu.php
  3. 22 7
      src/Store/Handle.php
  4. 6 0
      src/Store/Local.php
  5. 6 0
      src/Store/Qiniu.php
  6. 3 26
      src/View.php

+ 7 - 0
callback/qiniu.php

@@ -0,0 +1,7 @@
+<?php
+
+define('DEVER_DAEMON', true);
+
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../index.php');
+
+Dever::load('upload/qiniu.callback');

+ 56 - 0
src/Qiniu.php

@@ -0,0 +1,56 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| 查看图片的几个方法
+|--------------------------------------------------------------------------
+*/
+namespace Upload\Src;
+
+use Dever;
+Dever::apply('sdk/qiniu', 'upload');
+
+class Qiniu
+{
+	public function callback()
+	{
+		$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'];
+		$width = $body['width'];
+		$height = $body['height'];
+		$arr=array("date"=>"test");   
+		echo json_encode($arr);   
+	}
+
+    public function token()
+    {
+        $key = Dever::input('key');
+        $upload = Dever::db('upload/upload')->one($key);
+        if (!$upload) {
+            return;
+        }
+        
+        $config = Dever::db('upload/yun')->one($upload['yun']);
+        $accessKey = $config['appkey'];
+        $secretKey = $config['appsecret'];
+        $host = $config['host'];
+        $auth = new \Qiniu\Auth($accessKey, $secretKey);
+        $bucket = $upload['bucket'];
+
+        $policy = array(
+            'callbackUrl' => Dever::url('qiniu.callback', 'upload'),
+            'callbackBody' => 'filename=$(fname)&fkey=$(key)&filesize=$(fsize)&width=$(imageInfo.width)&height=$(imageInfo.height)'
+        );
+
+        // 生成上传Token
+        $token = $auth->uploadToken($bucket, null, 3600);
+
+        $domain = 'http://up-z1.qiniup.com/';
+        $ret = array('uptoken' => $token, 'domain' => $domain, 'host' => $config['host']);
+
+        echo json_encode($ret);die;
+    }
+}

+ 22 - 7
src/Store/Handle.php

@@ -31,12 +31,26 @@ class Handle
         }
     }
 
+    # 复制文件到服务器上
     public function copy()
+    {
+        return $this->get();
+    }
+
+    # 获取文件名
+    public function getName()
+    {
+        return $this->get('getName');
+    }
+
+
+    # 获取文件名
+    public function get($type = 'copy')
     {
         $yun = $local = array();
 
         if ($this->save_type <= 3) {
-            $local = $this->local->copy();
+            $local = $this->local->$type();
         }
 
         if ($local && $local['status'] == -1) {
@@ -44,15 +58,16 @@ class Handle
         }
 
         if ($this->save_type >= 2) {
-            $yun = $this->yun->copy();
+            $yun = $this->yun->$type();
         }
 
-        if ($this->local) {
-            $this->local->delete();
-        } elseif ($this->yun) {
-            $this->yun->delete();
+        if ($type == 'copy') {
+            if ($this->local) {
+                $this->local->delete();
+            } elseif ($this->yun) {
+                $this->yun->delete();
+            }
         }
-        
 
         if ($this->save_type <= 2) {
             return $local;

+ 6 - 0
src/Store/Local.php

@@ -59,6 +59,12 @@ class Local extends Core implements Config
 		}
 	}
 
+	public function getName()
+    {
+        $this->path()->name($this->data['file']['name'])->ext()->file();
+        return $this->file;
+    }
+
 	private function path()
 	{
 		$date = explode('-', date("Y-m-d"));

+ 6 - 0
src/Store/Qiniu.php

@@ -57,6 +57,12 @@ class Qiniu extends Core implements Config
         }
     }
 
+    public function getName()
+    {
+        $this->path()->name($this->data['file']['name'])->ext()->file();
+        return $this->file;
+    }
+
     private function path()
     {
         $date = explode('-', date("Y-m-d"));

+ 3 - 26
src/View.php

@@ -12,34 +12,11 @@ use Upload\Src\Lib\Img;
 
 class View
 {
-    public function token()
+    public function getFileName()
     {
-        $key = Dever::input('key');
-        $upload = Dever::db('upload/upload')->one($key);
-        if (!$upload) {
-            return;
-        }
-        Dever::apply('sdk/qiniu', 'upload');
-        $config = Dever::db('upload/yun')->one($upload['yun']);
-        $accessKey = $config['appkey'];
-        $secretKey = $config['appsecret'];
-        $this->host = $config['host'];
-        $auth = new \Qiniu\Auth($accessKey, $secretKey);
-        $bucket = $this->config['bucket'];
-
-        $policy = array(
-            'callbackUrl' => 'http://your.domain.com/upload_verify_callback.php',
-            'callbackBody' => 'filename=$(fname)&filesize=$(fsize)'
-        );
-
-        // 生成上传Token
-        $token = $auth->uploadToken($bucket, null, 3600);
-
-        $ret = array('uptoken' => $token);
-
-        echo json_encode($ret);die;
+        
     }
-
+    
     public function files()
     {
         $data = array();