123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | 处理云端图片的一些常用方法
- |--------------------------------------------------------------------------
- */
- namespace Upload\Src;
- use Dever;
- class Yun
- {
- # 查看视频截图
- public function cover($key, $video, $num = 1, $local = 2)
- {
- $domain = parse_url($video);
- $host = $domain['scheme'] . '://' . $domain['host'] . '/';
- $config = Dever::db('upload/yun')->one(array('host' => $host));
- if ($config) {
- return Dever::load('upload/lib/yun')->getMethod($config['type'])->cover($key, $video, $num, $local);
- }
- return false;
- }
- # 获取token
- public function token()
- {
- $return = Dever::input('return', 2);
- $key = Dever::input('key');
- $upload = Dever::db('upload/upload')->one($key);
- if (!$upload) {
- return;
- }
- if ($upload['save_type'] == 1) {
- return;
- }
- if (!$upload['yun']) {
- return;
- }
- $config = Dever::db('upload/yun')->one($upload['yun']);
- if (!$config) {
- return;
- }
- # 是否覆盖原文件,1是覆盖,2是不覆盖生成新文件
- $cover = 1;
- if ($upload['cover'] > 1) {
- $cover = 2;
- }
-
- list($type, $token, $domain, $bucket) = Dever::load('upload/lib/yun')->getMethod($config['type'])->token($config, $upload);
- $result = array('type' => $type, 'uptoken' => $token, 'domain' => $domain, 'host' => $config['host'], 'bucket' => $bucket, 'cover' => $cover);
- 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 = Dever::load('upload/lib/yun')->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) {
- Dever::load('upload/lib/yun')->getMethod($config['type'])->convert($key, $file, $config, $upload);
- }
- }
- $this->initFile($key, $file, $source, false, false, false, $search);
- }
- }
- }
|