Handle.php 2.3 KB

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