我正在尝试从我的网页上的单选按钮和提交按钮在我的服务器上执行bash脚本。有两个单选按钮,每个按钮将执行一个不同的bash脚本(test1.sh test2.sh)。这是我到目前为止所拥有的。
网页HTML:
<form action="testexec.php" method="get">
<label class="col">Up/Down</label>
<span class="col">
<input type="radio" name="option" id="r1" value="1" />
<label for="r1">Up</label>
<input type="radio" name="option" id="r2" value="2" />
<label for="r2">Down</label>
</span>
<span class="col">
<input type="submit" />
</span>
test1.sh/test2.sh (/var/www/html/testscripts)
#!/bin/bash
touch /tmp/testfile
ls -ltr /tmptestexec.php (与我的网页相同的目录)
<?php
$output = shell_exec("/var/www/html/testscript/test.sh");
header('Location: http://psat/moslehpour/dadt/main/systemTest.php?
success=true');
echo "<pre>$output</pre>"
?>当单击submit按钮时,我在服务器端看不到任何操作。此外,我如何验证正在发生的事情,我试图回显到网页,但似乎什么都没有显示。
发布于 2017-08-08 01:18:08
试试这样的东西。
<form action="testexec.php" method="POST">
<label class="col">Up/Down</label>
<span class="col">
<input type="radio" name="option" id="r1" >test1
<label for="r1">Up</label>
<input type="radio" name="option" id="r2" >test2
<label for="r2">Down</label>
</span>
<span class="col">
<input type="submit" /> <?php
//when the submit button is clicked
if ( $_SERVER['REQUEST_METHOD'] == 'POST'){
//name the radio 1 option1
if(isset($_POST['option']) && $_POST['option'] == 'test1' )
{ $output = shell_exec("/var/www/html/testscript/test.sh");}
//name the radio 2 option1
if(isset($_POST['option']) && $_POST['option'] == 'test2')
{ $output = shell_exec("/var/www/html/testscript/test.sh");}
//remove this if you want to see $output in this file
header('Location: http://psat/moslehpour/dadt/main/systemTest.php?
success=true');
echo "<pre>$output</pre>"
}
?>https://stackoverflow.com/questions/45552242
复制相似问题