Save.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. $pic = Dever::input('pic');
  18. $key = Dever::input('key');
  19. $local = Dever::local($pic);
  20. $img = Dever::input('img');
  21. $temp = explode('base64,', $img);
  22. $img = str_replace(' ', '+', $temp[1]);
  23. $img = base64_decode($img);
  24. $param = Dever::preInput('param');
  25. $name = implode('_', array_values($param));
  26. $local .= '.cr_' . $name . '.jpg';
  27. file_put_contents($local, $img);
  28. return Dever::pic($local);
  29. }
  30. private function upload($file = false, $key = 1)
  31. {
  32. $image['file'] = Dever::input('file', $file);
  33. $image['key'] = Dever::input('key', $key);
  34. //file_put_contents(DEVER_PATH . 'web/data/upload.txt', var_export($image, true));
  35. if ($image['file']) {
  36. if (isset($image['file'][0])) {
  37. $send = $image;
  38. foreach($image['file'] as $k => $v) {
  39. $send['file'] = $v;
  40. $handle = new Handle($send);
  41. $output = $handle->copy();
  42. unset($output['file']);
  43. $this->output[] = $output;
  44. }
  45. } else {
  46. $handle = new Handle($image);
  47. $this->output = $handle->copy();
  48. unset($this->output['file']);
  49. }
  50. }
  51. }
  52. public function copy($file = false, $key = 1, $state = false)
  53. {
  54. if (Dever::input('file') && $state == false) {
  55. $this->upload();
  56. Dever::outDiy($this->output);
  57. } else {
  58. $image['file'] = $file;
  59. $image['key'] = $key;
  60. $handle = new Handle($image);
  61. $this->output = $handle->copy();
  62. unset($this->output['file']);
  63. return $this->output;
  64. }
  65. }
  66. public function copys($file, $key = 1)
  67. {
  68. $file = urldecode($file);
  69. $file = explode(',', $file);
  70. foreach ($file as $v) {
  71. $copy = $this->copy($v, $key, true);
  72. if (isset($copy['url'])) {
  73. $result[] = $copy['url'];
  74. } else {
  75. $result[] = '';
  76. }
  77. }
  78. return implode(',', $result);
  79. }
  80. public function action_api()
  81. {
  82. $this->upload();
  83. Dever::outDiy($this->output);
  84. }
  85. public function start_api()
  86. {
  87. $this->upload();
  88. Dever::outDiy($this->output);
  89. }
  90. public function drag_api()
  91. {
  92. $this->upload();
  93. if ($this->output['status'] == 1) {
  94. $this->output['filename'] = $this->output['url'];
  95. } else {
  96. $this->output['error'] = $this->output['message'];
  97. }
  98. Dever::outDiy($this->output);
  99. }
  100. public function ueditor_api()
  101. {
  102. $this->upload();
  103. if ($this->output['status'] == 1) {
  104. $this->output['state'] = 'SUCCESS';
  105. $this->output['original'] = 1;
  106. } else {
  107. $this->output['url'] = '';
  108. $this->output['fileType'] = 1;
  109. $this->output['original'] = 1;
  110. $this->output['state'] = $this->output['message'];
  111. }
  112. Dever::outDiy($this->output);
  113. }
  114. public function simditor_api()
  115. {
  116. $this->upload();
  117. if ($this->output['status'] == 1) {
  118. $this->output['state'] = true;
  119. $this->output['file_path'] = $this->output['url'];
  120. } else {
  121. $this->output['state'] = false;
  122. }
  123. Dever::outDiy($this->output);
  124. }
  125. public function kindeditor_api()
  126. {
  127. $this->upload();
  128. if ($this->output['status'] == 1) {
  129. $this->output['error'] = 0;
  130. $this->output['url'] = $this->output['url'];
  131. } else {
  132. $this->output['error'] = 1;
  133. $this->output['message'] = $this->output['message'];
  134. }
  135. Dever::outDiy($this->output);
  136. }
  137. }