Handle.php 2.6 KB

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