Config.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Upload\Lib;
  3. use Dever;
  4. class Config
  5. {
  6. protected function file()
  7. {
  8. return Dever::data() . 'upload.php';
  9. }
  10. protected function import()
  11. {
  12. $file = $this->file();
  13. if (!is_file($file)) {
  14. $this->create();
  15. }
  16. $config = include($file);
  17. return $config;
  18. }
  19. public function get($id)
  20. {
  21. $config = $this->import();
  22. if (isset($config['upload'][$id])) {
  23. if ($config['upload'][$id]['save_type'] >= 2 && $config['upload'][$id]['yun'] > 0) {
  24. $config['upload'][$id]['yun'] = $config['yun'][$config['upload'][$id]['yun']];
  25. } else {
  26. $config['upload'][$id]['yun'] = false;
  27. }
  28. return $config['upload'][$id];
  29. }
  30. }
  31. # 从数据库生成维度和项目的配置文件
  32. public function create()
  33. {
  34. $config = array();
  35. $upload = Dever::db('upload/upload')->state();
  36. if ($upload) {
  37. foreach ($upload as $k => $v) {
  38. $config['upload'][$v['id']] = $v;
  39. }
  40. }
  41. $yun = Dever::db('upload/yun')->state();
  42. if ($yun) {
  43. foreach ($yun as $k => $v) {
  44. $config['yun'][$v['id']] = $v;
  45. }
  46. }
  47. $data = '<?php return ' . var_export($config, true) . ';';
  48. file_put_contents($this->file(), $data);
  49. return true;
  50. }
  51. }