<?php
session_start();
header('Content-type:application/json;charset=UTF-8');
$m = @$_POST["m"];
$md = @$_POST["md"];
$body = @$_POST["data"];
$pass = @$_POST["pass"];
if((int)$pass == 860712){
	if ($m == "newfile") {
		if (!is_file($md)) {
			$nf = file_put_contents($md, $body);
			if ($nf) {
				$msg["msg"] = "true";
			} else {
				$msg["msg"] = "新建文件出现错误,请重试!";
			}
		} else {
			$msg["msg"] = "文件已存在,请重新命名!";
		}
	} else if ($m == "savefile") {
		$sf = file_put_contents($md, $body);
		//$sf = fopen($md, 'w+');
		if ($sf) {
			//fwrite($sf, $body);
			$msg["msg"] = "true";
		} else {
			$msg["msg"] = "保存文件出现错误,请重试!";
		}
		//fclose($sf);
	}
} else {
	$msg["msg"] = "操作失败,密码错误!(MD记事本尚未完工,暂不对外开放)";
	setcookie('pass', NULL);
}
//$msg["post"] = $_POST;
echo json_encode($msg);
