Config.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. public function create_api()
  32. {}
  33. # 从数据库生成维度和项目的配置文件
  34. public function create()
  35. {
  36. $config = array();
  37. $upload = Dever::db('upload/upload')->state();
  38. if ($upload) {
  39. foreach ($upload as $k => $v) {
  40. $config['upload'][$v['id']] = $v;
  41. }
  42. }
  43. $yun = Dever::db('upload/yun')->state();
  44. if ($yun) {
  45. foreach ($yun as $k => $v) {
  46. $config['yun'][$v['id']] = $v;
  47. }
  48. }
  49. $data = '<?php return ' . var_export($config, true) . ';';
  50. file_put_contents($this->file(), $data);
  51. return true;
  52. }
  53. }