Handle.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. $class = 'Upload\Lib\Store\Qiniu';
  21. } elseif ($yun['type'] == 1) {
  22. $class = 'Upload\Lib\Store\Oss';
  23. }
  24. $data['host'] = $yun['host'];
  25. $this->yun = new $class($data);
  26. }
  27. if ($this->save_type <= 3) {
  28. $this->local = new Local($data);
  29. }
  30. }
  31. # 复制文件到服务器上
  32. public function copy()
  33. {
  34. return $this->get();
  35. }
  36. # 获取文件名
  37. public function name()
  38. {
  39. return $this->get('getName');
  40. }
  41. # 手动裁图
  42. public function cropper()
  43. {
  44. if ($this->local) {
  45. $this->local->cropper();
  46. }
  47. if ($this->yun) {
  48. $this->yun->cropper();
  49. }
  50. }
  51. # 获取文件名
  52. public function get($type = 'copy')
  53. {
  54. $yun = $local = array();
  55. if ($this->save_type <= 3) {
  56. $local = $this->local->$type();
  57. }
  58. if ($local && $local['status'] == -1) {
  59. return $local;
  60. }
  61. if ($this->save_type >= 2) {
  62. $yun = $this->yun->$type();
  63. }
  64. if ($type == 'copy') {
  65. if ($this->local) {
  66. $this->local->delete();
  67. } elseif ($this->yun) {
  68. $this->yun->delete();
  69. }
  70. }
  71. if ($this->save_type <= 2) {
  72. return $local;
  73. } elseif ($this->save_type > 2) {
  74. return $yun;
  75. }
  76. }
  77. public function handle_t($id, $source, $dest, $path)
  78. {
  79. $yun = $local = array();
  80. if ($this->save_type <= 3) {
  81. $local = $this->local->handle_t($id, $source, $dest);
  82. }
  83. if ($local) {
  84. return $local;
  85. }
  86. if ($this->save_type >= 2) {
  87. $yun = $this->yun->handle_t($id, $source, $dest, $path);
  88. }
  89. if ($this->save_type <= 2) {
  90. return $local;
  91. } elseif ($this->save_type > 2) {
  92. return $yun;
  93. }
  94. }
  95. }