File.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Upload\Lib;
  3. use Dever;
  4. class File
  5. {
  6. # 获取文件内容
  7. public function content($source)
  8. {
  9. if (strstr($source, '{uploadRes}')) {
  10. $source = Dever::local($source);
  11. $content = file_get_contents($source);
  12. return $content;
  13. } elseif (strstr($source, '{uploadYun}')) {
  14. $file = str_replace('{uploadYun}', '', $source);
  15. } elseif (strstr($source, 'http')) {
  16. $host = parse_url($source);
  17. $file = ltrim($host['path'], '/');
  18. }
  19. $temp = explode('/', $file);
  20. $key = $temp[0];
  21. $config = Dever::load('upload/lib/config')->get($key);
  22. if ($config) {
  23. if ($config['save_type'] >= 2 && $config['yun']) {
  24. if ($config['yun']['type'] == 2) {
  25. $class = 'Upload\Lib\View\Qiniu';
  26. } elseif ($config['yun']['type'] == 1) {
  27. $class = 'Upload\Lib\View\Oss';
  28. }
  29. $data['host'] = $config['yun']['host'];
  30. $yun = new $class();
  31. $file = $yun->connect($config['yun'], $config)->download($config['bucket'], $file);
  32. } else {
  33. $file = Dever::local($file);
  34. $file = file_get_contents($file);
  35. }
  36. } else {
  37. $file = Dever::curl($source);
  38. }
  39. return $file;
  40. }
  41. }