123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | 保存图片的几个方法
- |--------------------------------------------------------------------------
- */
- namespace Upload\Src;
- use Dever;
- use Upload\Lib\Store\Handle;
- class Save
- {
- public function __construct()
- {
-
- }
- public function cropper()
- {
- $send['param'] = Dever::preInput('param');
- $send['key'] = Dever::input('key');
- $send['pic'] = Dever::input('pic');
- $send['cate'] = 2;
- $send['name'] = 'cr_';
- $send['file'] = Dever::input('img');
- $send['cropper'] = true;
- $handle = new Handle($send);
- $this->output = $handle->copy();
- unset($this->output['file']);
-
- Dever::outDiy($this->output);
- }
- private function upload($file = false, $key = 1, $search = '', $search_key = '')
- {
- $files = Dever::preInput('files');
- $image['file'] = $files ? $files : Dever::input('file', $file);
- $image['key'] = Dever::input('key', $key);
- $image['search'] = Dever::input('search', $search);
- if ($image['search'] == 'undefined') {
- $image['search'] = '';
- }
- $search = Dever::input('search_key', $search_key);
- if ($search && $search > 0) {
- $image['search'] .= '_' . $search;
- }
- if (!$image['file'] || !$image['key']) {
- Dever::alert('传入参数错误');
- }
- //file_put_contents(Dever::data() . 'upload.txt', var_export($image, true));
- if ($image['file']) {
- if (is_array($image['file']) && (isset($image['file'][0]) || isset($image['file']['files_0']))) {
- $send = $image;
- foreach($image['file'] as $k => $v) {
- $send['file'] = $v;
- $handle = new Handle($send);
- $output = $handle->copy();
- unset($output['file']);
- $this->output[] = $output;
- }
- } else {
- $handle = new Handle($image);
- $this->output = $handle->copy();
- unset($this->output['file']);
- }
- $call = Dever::input('call');
- if ($call) {
- Dever::load($call, array('upload' => Dever::json_encode($this->output)), 'post');
- }
- }
- }
- public function copy($file = false, $key = 1, $state = false, $search = '', $ext = false, $name = false, $id = false)
- {
- if ($search == 'undefined') {
- $search = '';
- }
- if (Dever::input('file') && $state == false) {
- $this->upload();
- Dever::outDiy($this->output);
- } else {
- $image['file'] = $file;
- $image['key'] = $key;
- $image['search'] = $search;
- if ($ext) {
- $image['ext'] = $ext;
- }
- if ($name) {
- $image['name'] = $name;
- }
- if ($id) {
- $image['id'] = $id;
- }
-
- $handle = new Handle($image);
- $this->output = $handle->copy();
- unset($this->output['file']);
- return $this->output;
- }
- }
- public function copys($file, $key = 1, $search = '', $ext = false, $name = false)
- {
- $file = urldecode($file);
- $file = explode(',', $file);
- foreach ($file as $v) {
- $copy = $this->copy($v, $key, true, $search, $ext, $name);
- if (isset($copy['url'])) {
- $result[] = $copy['url'];
- } else {
- $result[] = '';
- }
- }
- return implode(',', $result);
- }
- public function action_api()
- {
- $this->upload();
- Dever::outDiy($this->output);
- }
- public function start_api()
- {
- $this->upload();
- Dever::outDiy($this->output);
- }
- public function drag_api()
- {
- $this->upload();
- if ($this->output['status'] == 1) {
- $this->output['filename'] = $this->output['url'];
- } else {
- $this->output['error'] = $this->output['message'];
- }
-
- Dever::outDiy($this->output);
- }
- public function ueditor_api()
- {
- $this->upload();
- if ($this->output['status'] == 1) {
- $this->output['state'] = 'SUCCESS';
- $this->output['original'] = 1;
- } else {
- $this->output['url'] = '';
- $this->output['fileType'] = 1;
- $this->output['original'] = 1;
- $this->output['state'] = $this->output['message'];
- }
-
- Dever::outDiy($this->output);
- }
- public function simditor_api()
- {
- $this->upload();
- if ($this->output['status'] == 1) {
- $this->output['state'] = true;
- $this->output['file_path'] = $this->output['url'];
- } else {
- $this->output['state'] = false;
- }
- Dever::outDiy($this->output);
- }
- public function kindeditor_api()
- {
- $this->upload();
- if ($this->output['status'] == 1) {
- $this->output['error'] = 0;
- $this->output['url'] = $this->output['url'];
- } else {
- $this->output['error'] = 1;
- $this->output['message'] = $this->output['message'];
- }
-
- Dever::outDiy($this->output);
- }
- }
|