0

我有两个相当简单的文件。第一个是这样的 HTML 文件:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<html>
<body>

<form action="test.php" method="post">
Search for: <input type="text" name="search" />
<input type="submit" name="submit" value="Search" />
</form>

</body>
</html>

第二个文件是 test.php,它看起来像这样:

<?
       $filepath = "/usr/sbin";
       exec("ONE $search -command $filepath ");
       fopen($filepath, rw);
?>

我的问题是我想使用 HTML 表单中给出的参数“搜索”作为 PHP 脚本中变量的值。ONE 是我制作的带有一个参数的搜索脚本,我希望它是“$search”。

可以这样做吗?如果可以,怎么做?

提前谢谢了。

4

2 回答 2

1

Just do this:

exec("ONE " . $_POST['search']. " -command $filepath ");

UPDATE:
You have another error, your following line:

fopen($filepath, rw);

should be like this:

fopen($filepath, "rw");

cause the second parameter to fopen() should be passed as a string.

UPDATE 2:
So as it seems, the OP want the output of the command to be printed on the page, for that you have to use passthru() instead of exec() , like so:

passthru("ONE " . $_POST['search']. " -command $filepath ");
于 2012-09-19T17:49:02.873 回答
1

您可以使用访问该变量$_POST['search']

在 shell 调用中使用它之前,您应该确保它不会损坏您的系统。

于 2012-09-19T17:49:19.937 回答