【发布时间】:2017-06-20 16:12:30
【问题描述】:
我在树莓派上有一个 apache 服务器。我有一个基本程序,用户在其中将字符串输入到 html 表单框中。单击提交将条目发送到 php 文件,然后该文件调用 shell 脚本,并将条目作为提示传递。如果你看下面的 php,它有一个带有用户输入的变量,它调用 shell 文件 main.sh。如何提供该变量作为输入的 shell 程序。我查看了 proc_open,但无法让它工作。谢谢 索引.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="script.php" method="post" enctype="multipart/form-data">
Address: <input type="text" name="Address" value=""><br>
<input type="submit" value="Upload" name="submit">
</form>
</body>
</html>
script.php:
<?php
if(isset($_POST["submit"])) {
if($_POST['Address'] != "")
{
$entry = $_POST['Address'];
$output = shell_exec ("./main.sh");
echo $output;
}
}
?>
最后是 shell 文件:main.sh:
echo -n "Do you like pie (y/n)? "
read answer
if echo "$answer" | grep -iq "^y" ;then
echo Yes
else
echo No
fi
【问题讨论】: