Handle.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 get($type = 'copy')
  39. {
  40. $yun = $local = array();
  41. if ($this->save_type <= 3) {
  42. $local = $this->local->$type();
  43. }
  44. if ($local && $local['status'] == -1) {
  45. return $local;
  46. }
  47. if ($this->save_type >= 2) {
  48. $yun = $this->yun->$type();
  49. }
  50. if ($type == 'copy') {
  51. if ($this->local) {
  52. $this->local->delete();
  53. } elseif ($this->yun) {
  54. $this->yun->delete();
  55. }
  56. }
  57. if ($this->save_type <= 2) {
  58. return $local;
  59. } elseif ($this->save_type > 2) {
  60. return $yun;
  61. }
  62. }
  63. public function handle_t($id, $source, $dest, $path)
  64. {
  65. $yun = $local = array();
  66. if ($this->save_type <= 3) {
  67. $local = $this->local->handle_t($id, $source, $dest);
  68. }
  69. if ($local) {
  70. return $local;
  71. }
  72. if ($this->save_type >= 2) {
  73. $yun = $this->yun->handle_t($id, $source, $dest, $path);
  74. }
  75. if ($this->save_type <= 2) {
  76. return $local;
  77. } elseif ($this->save_type > 2) {
  78. return $yun;
  79. }
  80. }
  81. }