Yun.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Upload\Lib;
  3. use Dever;
  4. class Yun
  5. {
  6. public function get($id)
  7. {
  8. $upload = Dever::db('upload/upload')->one($id);
  9. if (!$upload) {
  10. return false;
  11. }
  12. if ($upload['save_type'] == 1) {
  13. return false;
  14. }
  15. if (!$upload['yun']) {
  16. return false;
  17. }
  18. $config = Dever::db('upload/yun')->one($upload['yun']);
  19. if (!$config) {
  20. return false;
  21. }
  22. return $config;
  23. }
  24. public function view($file)
  25. {
  26. $data = parse_url($file);
  27. $path = ltrim($data['path'], '/');
  28. $temp = explode('/', $path);
  29. $config = $this->get($temp[0]);
  30. if (!$config) {
  31. return $file;
  32. }
  33. return Dever::load('upload/lib/yun')->getMethod($config['type'])->view($config, $file);
  34. }
  35. public function getMethod($type)
  36. {
  37. if ($type == 1) {
  38. $method = 'oss';
  39. } else {
  40. $method = 'qiniu';
  41. }
  42. return Dever::load('upload/lib/view/' . $method);
  43. }
  44. }