File.php 1.2 KB

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