one(array('host' => $host)); if ($config) { return $this->getMethod($config['type'])->cover($key, $video); } 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) = $this->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 = $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($config['type'])->convert($key, $file, $config, $upload); } } $this->initFile($key, $file, $source, false, false, false, $search); } } }