首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用php执行bash脚本的HTML表单单选按钮。

使用php执行bash脚本的HTML表单单选按钮。
EN

Stack Overflow用户
提问于 2017-08-08 01:10:27
回答 1查看 692关注 0票数 1

我正在尝试从我的网页上的单选按钮和提交按钮在我的服务器上执行bash脚本。有两个单选按钮,每个按钮将执行一个不同的bash脚本(test1.sh test2.sh)。这是我到目前为止所拥有的。

网页HTML:

代码语言:javascript
复制
<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)

代码语言:javascript
复制
#!/bin/bash
touch /tmp/testfile
ls -ltr /tmp

testexec.php (与我的网页相同的目录)

代码语言:javascript
复制
<?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按钮时,我在服务器端看不到任何操作。此外,我如何验证正在发生的事情,我试图回显到网页,但似乎什么都没有显示。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-08 01:18:08

试试这样的东西。

代码语言:javascript
复制
 <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" />
代码语言:javascript
复制
 <?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>"
 } 
 ?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45552242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档