Save.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. }
  62. }
  63. public function copy($file = false, $key = 1, $state = false, $search = '')
  64. {
  65. if ($search == 'undefined') {
  66. $search = '';
  67. }
  68. if (Dever::input('file') && $state == false) {
  69. $this->upload();
  70. Dever::outDiy($this->output);
  71. } else {
  72. $image['file'] = $file;
  73. $image['key'] = $key;
  74. $image['search'] = $search;
  75. $handle = new Handle($image);
  76. $this->output = $handle->copy();
  77. unset($this->output['file']);
  78. return $this->output;
  79. }
  80. }
  81. public function copys($file, $key = 1, $search = '')
  82. {
  83. $file = urldecode($file);
  84. $file = explode(',', $file);
  85. foreach ($file as $v) {
  86. $copy = $this->copy($v, $key, true, $search);
  87. if (isset($copy['url'])) {
  88. $result[] = $copy['url'];
  89. } else {
  90. $result[] = '';
  91. }
  92. }
  93. return implode(',', $result);
  94. }
  95. public function action_api()
  96. {
  97. $this->upload();
  98. Dever::outDiy($this->output);
  99. }
  100. public function start_api()
  101. {
  102. $this->upload();
  103. Dever::outDiy($this->output);
  104. }
  105. public function drag_api()
  106. {
  107. $this->upload();
  108. if ($this->output['status'] == 1) {
  109. $this->output['filename'] = $this->output['url'];
  110. } else {
  111. $this->output['error'] = $this->output['message'];
  112. }
  113. Dever::outDiy($this->output);
  114. }
  115. public function ueditor_api()
  116. {
  117. $this->upload();
  118. if ($this->output['status'] == 1) {
  119. $this->output['state'] = 'SUCCESS';
  120. $this->output['original'] = 1;
  121. } else {
  122. $this->output['url'] = '';
  123. $this->output['fileType'] = 1;
  124. $this->output['original'] = 1;
  125. $this->output['state'] = $this->output['message'];
  126. }
  127. Dever::outDiy($this->output);
  128. }
  129. public function simditor_api()
  130. {
  131. $this->upload();
  132. if ($this->output['status'] == 1) {
  133. $this->output['state'] = true;
  134. $this->output['file_path'] = $this->output['url'];
  135. } else {
  136. $this->output['state'] = false;
  137. }
  138. Dever::outDiy($this->output);
  139. }
  140. public function kindeditor_api()
  141. {
  142. $this->upload();
  143. if ($this->output['status'] == 1) {
  144. $this->output['error'] = 0;
  145. $this->output['url'] = $this->output['url'];
  146. } else {
  147. $this->output['error'] = 1;
  148. $this->output['message'] = $this->output['message'];
  149. }
  150. Dever::outDiy($this->output);
  151. }
  152. }