Nov 9
PHP AJAX demo——操作文本文件
学习
JS代码
后台代码operation.php:
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: text/html;charset=utf-8');
if(strip_tags($_GET['action'])=='read')
{
//读取文件
echo nl2br(file_get_contents("demo.txt"));
}else{
//写入文件
$content=$_POST['content'];
file_put_contents('demo.txt',$content);
echo nl2br(file_get_contents("demo.txt"));
}
?>
后台代码operation.php:
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: text/html;charset=utf-8');
if(strip_tags($_GET['action'])=='read')
{
//读取文件
echo nl2br(file_get_contents("demo.txt"));
}else{
//写入文件
$content=$_POST['content'];
file_put_contents('demo.txt',$content);
echo nl2br(file_get_contents("demo.txt"));
}
?>
最新评论及回复