Save.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | 保存图片的几个方法
  5. |--------------------------------------------------------------------------
  6. */
  7. namespace Upload\Src;
  8. use Dever;
  9. use Upload\Lib\Store\Handle;
  10. class Save
  11. {
  12. public function __construct()
  13. {
  14. }
  15. public function cropper()
  16. {
  17. $send['param'] = Dever::preInput('param');
  18. $send['key'] = Dever::input('key');
  19. $send['pic'] = Dever::input('pic');
  20. $send['cate'] = 2;
  21. $send['name'] = 'cr_';
  22. $send['file'] = Dever::input('img');
  23. $send['cropper'] = true;
  24. $handle = new Handle($send);
  25. $this->output = $handle->copy();
  26. unset($this->output['file']);
  27. Dever::outDiy($this->output);
  28. }
  29. private function upload($file = false, $key = 1, $search = '', $search_key = '')
  30. {
  31. $files = Dever::preInput('files');
  32. $image['file'] = $files ? $files : Dever::input('file', $file);
  33. $image['key'] = Dever::input('key', $key);
  34. $image['search'] = Dever::input('search', $search);
  35. if ($image['search'] == 'undefined') {
  36. $image['search'] = '';
  37. }
  38. $search = Dever::input('search_key', $search_key);
  39. if ($search && $search > 0) {
  40. $image['search'] .= '_' . $search;
  41. }
  42. if (!$image['file'] || !$image['key']) {
  43. Dever::alert('传入参数错误');
  44. }
  45. //file_put_contents(Dever::data() . 'upload.txt', var_export($image, true));
  46. if ($image['file']) {
  47. if (is_array($image['file']) && (isset($image['file'][0]) || isset($image['file']['files_0']))) {
  48. $send = $image;
  49. foreach($image['file'] as $k => $v) {
  50. $send['file'] = $v;
  51. $handle = new Handle($send);
  52. $output = $handle->copy();
  53. unset($output['file']);
  54. $this->output[] = $output;
  55. }
  56. } else {
  57. $handle = new Handle($image);
  58. $this->output = $handle->copy();
  59. unset($this->output['file']);
  60. }
  61. $call = Dever::input('call');
  62. if ($call) {
  63. Dever::load($call, array('upload' => Dever::json_encode($this->output)), 'post');
  64. }
  65. }
  66. }
  67. public function copy($file = false, $key = 1, $state = false, $search = '', $ext = false, $name = false, $id = false)
  68. {
  69. if ($search == 'undefined') {
  70. $search = '';
  71. }
  72. if (Dever::input('file') && $state == false) {
  73. $this->upload();
  74. Dever::outDiy($this->output);
  75. } else {
  76. $image['file'] = $file;
  77. $image['key'] = $key;
  78. $image['search'] = $search;
  79. if ($ext) {
  80. $image['ext'] = $ext;
  81. }
  82. if ($name) {
  83. $image['name'] = $name;
  84. }
  85. if ($id) {
  86. $image['id'] = $id;
  87. }
  88. $handle = new Handle($image);
  89. $this->output = $handle->copy();
  90. unset($this->output['file']);
  91. return $this->output;
  92. }
  93. }
  94. public function copys($file, $key = 1, $search = '', $ext = false, $name = false)
  95. {
  96. $file = urldecode($file);
  97. $file = explode(',', $file);
  98. foreach ($file as $v) {
  99. $copy = $this->copy($v, $key, true, $search, $ext, $name);
  100. if (isset($copy['url'])) {
  101. $result[] = $copy['url'];
  102. } else {
  103. $result[] = '';
  104. }
  105. }
  106. return implode(',', $result);
  107. }
  108. public function action_api()
  109. {
  110. $this->upload();
  111. Dever::outDiy($this->output);
  112. }
  113. public function start_api()
  114. {
  115. $this->upload();
  116. Dever::outDiy($this->output);
  117. }
  118. public function drag_api()
  119. {
  120. $this->upload();
  121. if ($this->output['status'] == 1) {
  122. $this->output['filename'] = $this->output['url'];
  123. } else {
  124. $this->output['error'] = $this->output['message'];
  125. }
  126. Dever::outDiy($this->output);
  127. }
  128. public function ueditor_api()
  129. {
  130. $this->upload();
  131. if ($this->output['status'] == 1) {
  132. $this->output['state'] = 'SUCCESS';
  133. $this->output['original'] = 1;
  134. } else {
  135. $this->output['url'] = '';
  136. $this->output['fileType'] = 1;
  137. $this->output['original'] = 1;
  138. $this->output['state'] = $this->output['message'];
  139. }
  140. Dever::outDiy($this->output);
  141. }
  142. public function simditor_api()
  143. {
  144. $this->upload();
  145. if ($this->output['status'] == 1) {
  146. $this->output['state'] = true;
  147. $this->output['file_path'] = $this->output['url'];
  148. } else {
  149. $this->output['state'] = false;
  150. }
  151. Dever::outDiy($this->output);
  152. }
  153. public function kindeditor_api()
  154. {
  155. $this->upload();
  156. if ($this->output['status'] == 1) {
  157. $this->output['error'] = 0;
  158. $this->output['url'] = $this->output['url'];
  159. } else {
  160. $this->output['error'] = 1;
  161. $this->output['message'] = $this->output['message'];
  162. }
  163. Dever::outDiy($this->output);
  164. }
  165. }