123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace Upload\Lib;
- use Dever;
- class Config
- {
- protected function file()
- {
- return Dever::data() . 'upload.php';
- }
- protected function import()
- {
- $file = $this->file();
- if (!is_file($file)) {
- $this->create();
- }
- $config = include($file);
- return $config;
- }
- public function get($id)
- {
- $config = $this->import();
- if (isset($config['upload'][$id])) {
- if ($config['upload'][$id]['save_type'] >= 2 && $config['upload'][$id]['yun'] > 0) {
- $config['upload'][$id]['yun'] = $config['yun'][$config['upload'][$id]['yun']];
- } else {
- $config['upload'][$id]['yun'] = false;
- }
- return $config['upload'][$id];
- }
- }
- # 从数据库生成维度和项目的配置文件
- public function create()
- {
- $config = array();
- $upload = Dever::db('upload/upload')->state();
- if ($upload) {
- foreach ($upload as $k => $v) {
- $config['upload'][$v['id']] = $v;
- }
- }
- $yun = Dever::db('upload/yun')->state();
- if ($yun) {
- foreach ($yun as $k => $v) {
- $config['yun'][$v['id']] = $v;
- }
- }
- $data = '<?php return ' . var_export($config, true) . ';';
- file_put_contents($this->file(), $data);
- return true;
- }
- }
|