|
@@ -0,0 +1,133 @@
|
|
|
|
+<?php
|
|
|
|
+/*
|
|
|
|
+|--------------------------------------------------------------------------
|
|
|
|
+| 处理云端图片的一些常用方法
|
|
|
|
+|--------------------------------------------------------------------------
|
|
|
|
+*/
|
|
|
|
+namespace Upload\Src;
|
|
|
|
+
|
|
|
|
+use Dever;
|
|
|
|
+
|
|
|
|
+class Yun
|
|
|
|
+{
|
|
|
|
+ private function getMethod($type)
|
|
|
|
+ {
|
|
|
|
+ if ($type == 1) {
|
|
|
|
+ $method = 'oss';
|
|
|
|
+ } else {
|
|
|
|
+ $method = 'qiniu';
|
|
|
|
+ }
|
|
|
|
+ return Dever::load('upload/lib/view/' . $method);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function token()
|
|
|
|
+ {
|
|
|
|
+ $return = Dever::input('return', 2);
|
|
|
|
+ $key = Dever::input('key');
|
|
|
|
+ $upload = Dever::db('upload/upload')->one($key);
|
|
|
|
+ if (!$upload) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!$upload['yun']) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ $config = Dever::db('upload/yun')->one($upload['yun']);
|
|
|
|
+ if (!$config) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ list($type, $token, $domain) = $this->getMethod($config['type'])->token($config, $upload);
|
|
|
|
+ $result = array('type' => $type, 'uptoken' => $token, 'domain' => $domain, 'host' => $config['host']);
|
|
|
|
+ if ($return == 1) {
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
|
|
+ echo json_encode($result);die;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function callback()
|
|
|
|
+ {
|
|
|
|
+ $config = Dever::input('config');
|
|
|
|
+ if (!$config) {
|
|
|
|
+ return 'error';
|
|
|
|
+ }
|
|
|
|
+ $config = Dever::db('upload/yun')->one($config);
|
|
|
|
+ if (!$config) {
|
|
|
|
+ return 'error';
|
|
|
|
+ }
|
|
|
|
+ $body = $this->getMethod($config['type'])->callback();
|
|
|
|
+ $file = $body['filename'];
|
|
|
|
+ $key = $body['key'];
|
|
|
|
+ $size = $body['filesize'];
|
|
|
|
+ $width = $body['width'];
|
|
|
|
+ $height = $body['height'];
|
|
|
|
+
|
|
|
|
+ $upload = Dever::db('upload/upload')->one($key);
|
|
|
|
+ if ($upload) {
|
|
|
|
+ $this->initFile($key, $file, $file, $width, $height, $size);
|
|
|
|
+ }
|
|
|
|
+ return 'ok';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function initFile($key, $file, $source, $width = false, $height = false, $size = false, $search = '')
|
|
|
|
+ {
|
|
|
|
+ $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 ($search) {
|
|
|
|
+ $data['search'] = $search;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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');
|
|
|
|
+ $search = Dever::input('search');
|
|
|
|
+
|
|
|
|
+ $upload = Dever::db('upload/upload')->one($key);
|
|
|
|
+
|
|
|
|
+ if ($upload) {
|
|
|
|
+
|
|
|
|
+ if ($upload['yun'] > 0 && $upload['vod_convert'] == 2) {
|
|
|
|
+ $config = Dever::db('upload/yun')->one($upload['yun']);
|
|
|
|
+ if ($config) {
|
|
|
|
+ $this->getMethod($method)->convert($key, $file, $config, $upload);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $this->initFile($key, $file, $source, false, false, false, $search);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|