Handle.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace Upload\Lib\Store;
  3. use Dever;
  4. class Handle
  5. {
  6. /**
  7. * __construct
  8. *
  9. * @return mixed
  10. */
  11. public function __construct($data = array())
  12. {
  13. $this->yun = $this->local = false;
  14. $config = Dever::db('upload/upload')->one($data['key']);
  15. $this->save_type = $config['save_type'];
  16. $yun = $config['yun'];
  17. if ($this->save_type >= 2) {
  18. $yun = Dever::db('upload/yun')->one($yun);
  19. if ($yun['type'] == 2) {
  20. $yun = 'Upload\Lib\Store\Qiniu';
  21. } elseif ($yun['type'] == 1) {
  22. $yun = 'Upload\Lib\Store\Oss';
  23. }
  24. $this->yun = new $yun($data);
  25. }
  26. if ($this->save_type <= 3) {
  27. $this->local = new Local($data);
  28. }
  29. }
  30. # 复制文件到服务器上
  31. public function copy()
  32. {
  33. return $this->get();
  34. }
  35. # 获取文件名
  36. public function name()
  37. {
  38. return $this->get('getName');
  39. }
  40. # 手动裁图
  41. public function cropper()
  42. {
  43. if ($this->local) {
  44. $this->local->cropper();
  45. }
  46. if ($this->yun) {
  47. $this->yun->cropper();
  48. }
  49. }
  50. # 获取文件名
  51. public function get($type = 'copy')
  52. {
  53. $yun = $local = array();
  54. if ($this->save_type <= 3) {
  55. $local = $this->local->$type();
  56. }
  57. if ($local && $local['status'] == -1) {
  58. return $local;
  59. }
  60. if ($this->save_type >= 2) {
  61. $yun = $this->yun->$type();
  62. }
  63. if ($type == 'copy') {
  64. if ($this->local) {
  65. $this->local->delete();
  66. } elseif ($this->yun) {
  67. $this->yun->delete();
  68. }
  69. }
  70. if ($this->save_type <= 2) {
  71. return $local;
  72. } elseif ($this->save_type > 2) {
  73. return $yun;
  74. }
  75. }
  76. public function handle_t($id, $source, $dest, $path)
  77. {
  78. $yun = $local = array();
  79. if ($this->save_type <= 3) {
  80. $local = $this->local->handle_t($id, $source, $dest);
  81. }
  82. if ($local) {
  83. return $local;
  84. }
  85. if ($this->save_type >= 2) {
  86. $yun = $this->yun->handle_t($id, $source, $dest, $path);
  87. }
  88. if ($this->save_type <= 2) {
  89. return $local;
  90. } elseif ($this->save_type > 2) {
  91. return $yun;
  92. }
  93. }
  94. }