从php按钮

时间:2017-05-27 02:37:32

标签: javascript php linux

我想通过PHP在Linux服务器上测试4个文件,显示结果应显示在文本区域中。让我知道解决这个问题的正确方法。

sh test_batch.sh

$ {dict_file} $ {locale} $ {keyboard_layout} $ {golden_test_file} $ 
{auto_correction_file} (optional)

those are the four files with check box

 if (isset($_POST['files'])) {
 foreach ($_POST['files'] as $value) {
 echo $dir . $value . '<br />';
 $result = shell_exec('sudo sh test_batch.sh $dir .$value. ');

  }
  }else {
  exit('No files selected');
  }
  }
   ?>
                            <br/>
                            <table>
                             <tr>
                    <td><b>Result to Display and Save:</b></td></tr>
            <tr>
                    <td colspan="3">
                    <textarea disabled id="inputTextToSave"  style="width:512px;height:256px" value = "'.$result.'"></textarea>`

1 个答案:

答案 0 :(得分:0)

首先,您应该避免在Web脚本中使用sudo来执行任何操作。如果有人决定在你的$ _POST中为你的服务器提供字符串“&amp;&amp; rm -rf /”并且它已连接到你的 sudo sh test_batch.sh $ dir。$ value 字符串?这将是一个非常糟糕的一天。

相反,考虑将某些test_batch.sh实现到某种处理排队到它的请求的工作脚本(你可以在Perl,PHP中使用Node.JS这样做......有几种方法。