Save.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | 保存图片的几个方法
  5. |--------------------------------------------------------------------------
  6. */
  7. namespace Upload\Src;
  8. use Dever;
  9. use Upload\Src\Store\Handle;
  10. class Save
  11. {
  12. public function __construct()
  13. {
  14. $image['file'] = Dever::input('file');
  15. $image['key'] = Dever::input('key');
  16. //file_put_contents(DEVER_PATH . 'web/data/upload.txt', var_export($image, true));
  17. if ($image['file']) {
  18. $handle = new Handle($image);
  19. $this->output = $handle->copy();
  20. unset($this->output['file']);
  21. }
  22. }
  23. public function copy($file, $key = 1)
  24. {
  25. $image['file'] = $file;
  26. $image['key'] = $key;
  27. $handle = new Handle($image);
  28. $this->output = $handle->copy();
  29. unset($this->output['file']);
  30. return $this->output;
  31. }
  32. public function copys($file, $key = 1)
  33. {
  34. $file = urldecode($file);
  35. $file = explode(',', $file);
  36. foreach ($file as $v) {
  37. $copy = $this->copy($v, $key);
  38. if (isset($copy['url'])) {
  39. $result[] = $copy['url'];
  40. } else {
  41. $result[] = '';
  42. }
  43. }
  44. return implode(',', $result);
  45. }
  46. public function action_api()
  47. {
  48. Dever::outDiy($this->output);
  49. }
  50. public function start_api()
  51. {
  52. Dever::outDiy($this->output);
  53. }
  54. public function drag_api()
  55. {
  56. if ($this->output['status'] == 1) {
  57. $this->output['filename'] = $this->output['url'];
  58. } else {
  59. $this->output['error'] = $this->output['message'];
  60. }
  61. Dever::outDiy($this->output);
  62. }
  63. public function ueditor_api()
  64. {
  65. if ($this->output['status'] == 1) {
  66. $this->output['state'] = 'SUCCESS';
  67. $this->output['original'] = 1;
  68. } else {
  69. $this->output['url'] = '';
  70. $this->output['fileType'] = 1;
  71. $this->output['original'] = 1;
  72. $this->output['state'] = $this->output['message'];
  73. }
  74. Dever::outDiy($this->output);
  75. }
  76. public function simditor_api()
  77. {
  78. if ($this->output['status'] == 1) {
  79. $this->output['state'] = true;
  80. $this->output['file_path'] = $this->output['url'];
  81. } else {
  82. $this->output['state'] = false;
  83. }
  84. Dever::outDiy($this->output);
  85. }
  86. public function kindeditor_api()
  87. {
  88. if ($this->output['status'] == 1) {
  89. $this->output['error'] = 0;
  90. $this->output['url'] = $this->output['url'];
  91. } else {
  92. $this->output['error'] = 1;
  93. $this->output['message'] = $this->output['message'];
  94. }
  95. Dever::outDiy($this->output);
  96. }
  97. }