123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace Upload\Lib\Store;
- use Dever;
- class Handle
- {
- /**
- * __construct
- *
- * @return mixed
- */
- public function __construct($data = array())
- {
- $this->yun = $this->local = false;
- $config = Dever::load('upload/lib/config')->get($data['key']);
- //$config = Dever::db('upload/upload')->one($data['key']);
- if (!$config) {
- Dever::alert('错误的上传配置');
- return;
- }
- if (isset($data['yun']) && $data['yun']) {
- $config['save_type'] = 4;
- $config['yun'] = $data['yun'];
- }
- $this->save_type = $config['save_type'];
- if ($this->save_type >= 2 && $config['yun']) {
- if ($config['yun']['type'] == 2) {
- $class = 'Upload\Lib\Store\Qiniu';
- } elseif ($config['yun']['type'] == 1) {
- $class = 'Upload\Lib\Store\Oss';
- } elseif ($config['yun']['type'] == 3) {
- $class = 'Upload\Lib\Store\Sina';
- }
- $data['host'] = $config['yun']['host'];
-
- $this->yun = new $class($config, $data);
- }
- if ($this->save_type <= 3) {
- $this->local = new Local($config, $data);
- }
- }
- # 复制文件到服务器上
- public function copy()
- {
- return $this->get();
- }
- # 获取文件名
- public function name()
- {
- return $this->get('getName');
- }
- # 手动裁图
- public function cropper()
- {
- if ($this->local) {
- $this->local->cropper();
- }
- if ($this->yun) {
- $this->yun->cropper();
- }
- }
- # 获取文件名
- public function get($type = 'copy')
- {
- $yun = $local = array();
- if ($this->save_type <= 3) {
- $local = $this->local->$type();
- }
- if ($local && $local['status'] == -1) {
- return $local;
- }
- if ($this->save_type >= 2) {
- $yun = $this->yun->$type();
- }
- if ($type == 'copy') {
- if ($this->local) {
- $this->local->delete();
- } elseif ($this->yun) {
- $this->yun->delete();
- }
- }
- if ($this->save_type <= 2) {
- return $local;
- } elseif ($this->save_type > 2) {
- return $yun;
- }
- }
- public function handle_t($id, $source, $dest, $path)
- {
- $yun = $local = array();
- if ($this->save_type <= 3) {
- $local = $this->local->handle_t($id, $source, $dest);
- }
- if ($local) {
- return $local;
- }
- if ($this->save_type >= 2) {
- $yun = $this->yun->handle_t($id, $source, $dest, $path);
- }
- if ($this->save_type <= 2) {
- return $local;
- } elseif ($this->save_type > 2) {
- return $yun;
- }
- }
- public function handle_c($id, $source, $dest, $path)
- {
- $yun = $local = array();
- if ($this->save_type <= 3) {
- $local = $this->local->handle_c($id, $source, $dest);
- }
- if ($local) {
- return $local;
- }
- if ($this->save_type >= 2) {
- $yun = $this->yun->handle_c($id, $source, $dest, $path);
- }
- if ($this->save_type <= 2) {
- return $local;
- } elseif ($this->save_type > 2) {
- return $yun;
- }
- }
- }
|