php 写txt文件

写txt文件,代码示例:

//接收数据入文件
$year = date('Y');
$month = date('m');
$day = date('d');
$time = date('H:i:s');
$route = dirname(dirname(dirname(__FILE__))); 
$path = "$route\\txt\\$year\\$month";
$uri = $_SERVER["REQUEST_URI"];
if (!file_exists($path)){
        //设定目录的权限,默认是 0777,意味着最大可能的访问权,在 Windows 下被忽略
	mkdir ($path,0644,true);
	echo '创建文件夹成功';
	$data = json_encode($_GET);
	file_put_contents("$path\\$day.txt","$data\r\n",FILE_APPEND);
} else {
	echo '需创建的文件夹已经存在';
	$data = json_encode($_GET);
	file_put_contents("$path\\$day.txt","$data\r\n",FILE_APPEND);
}

猜你喜欢

转载自blog.csdn.net/weixin_43652106/article/details/85012930