我正在尝试创建一个php \ shell脚本来创建一个文件。我使用exec()命令来创建shell和php本身之间的链接。我也试图从用户那里接收数据,为此我有一个链接到脚本的php表单页面。
<?php
$username = $_POST['txt_username'];
exec("sudo echo $username > file.txt");
?>
从我的研究中我发现exec()不接受$ _POST或$ _GET变量。我还尝试过extract(),getenv()和var_dump()等函数,以及escapeshellcmd()和escapeshellarg()。有人能帮助我吗?
答案 0 :(得分:1)
这就是你在寻找什么?
<?php
$uname = $_POST['UserName'];
$file_to_write = "file.txt";
$open_file = fopen($file_to_write,'w') or die ("Cant Open File");
fwrite($file_to_write, $uname);
flcose($file_to_write);
?>
答案 1 :(得分:1)
我会这样做。
<?php
file_put_contents( 'file.txt', $_POST['txt_username'] );
?>