Save.php 3.8 KB

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