网站配置项上传文件(LOGO)

在程序./Application/Common/Conf目录下新建一个System.php文件,用于存放数据,并在config.php文件中调用该文件配置

//扩展配置
'LOAD_EXT_CONFIG' => 'system',

新建一个控制器

<?php
namespace Tdcq\Controller;
use Think\Controller;
class SystemController extends BaseController {
    public function index(){
    if(IS_POST){
    $file='./Etc/Common/Conf/system.php';
    $pic=array();
            //上传图片
            if($_FILES != ''){
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     0 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg','bmp');// 设置附件上传类型
                $upload->rootPath='./';
                $upload->savePath  =      'Public/Logo/'; // 设置附件上传目录
                $info=$upload->upload($_FILES);


                    foreach ($info as $k => $v) {
                            $pic[$k]=$v['savepath'].$v['savename'];
                        }
                }
            
            $post=$_POST;
            $post=array_merge($pic,$post);
            $post=array_change_key_case($post,CASE_UPPER);
            $config=array_merge(include $file,$post);
            $config=var_export($config,true);
            $str="<?php\r\nreturn ".$config.";";
                if(file_put_contents($file,$str)){
                    $this->success('修改成功');
                }else{
                    $this->error('修改失败');
                }
            return;
            
    }
$this->display();
    } 


    public function del(){
       $pic1=I('path.2');
       $pic2=I('path.3');
       $pic3=I('path.4');
       $pic4=I('path.5');
       $pic=$pic1.'/'.$pic2.'/'.$pic3.'/'.$pic4;
       $pic=str_replace("'","",$pic);
       $file='./Etc/Common/Conf/system.php';
        if($pic){
            if(unlink($pic)){
                    //读取文件
                    $origin_str = file_get_contents($file);
                    
                    //修改内容
                    $update_str = str_replace($pic, '', file_get_contents($file));
                    //写入保存
                    file_put_contents($file, $update_str);
                    $this->success("删除图片成功");
            }else{
                    $this->error('删除图片失败');
            }
        }


       
    }
}



                                      <label class="col-sm-2 control-label">LOGO</label>
                                      <div class="col-sm-10">
                                        <if condition="$Think.config.LOGO neq ''">
                                            
                                            <img src="__ROOT__/{$Think.config.LOGO}" height="50">
                                            <a href="__CONTROLLER__/del/'{$Think.config.LOGO}'" />删除</a>
                                            <else/>
                                            <input name="logo" type="file" class="form-control" >
                                        </if>
                                          
                                          
                                      </div>
                                  </div>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值