Javascript 以PHP格式从文本框和文件输入

Javascript 以PHP格式从文本框和文件输入,javascript,php,html,shell,Javascript,Php,Html,Shell,我试着制作一个html和php页面,分别用于输入和处理它们。在HTML页面中,用户可以选择提供文本或上载文件 <form action="target.php" method='POST' enctype="multipart/form-data" id="form"> <table width="950px" align="center"> <tr> <table width="100%" align="center" cell

我试着制作一个html和php页面,分别用于输入和处理它们。在HTML页面中,用户可以选择提供文本或上载文件

<form action="target.php" method='POST' enctype="multipart/form-data"            id="form">
<table  width="950px" align="center">
<tr>
<table width="100%" align="center" cellpadding="0" cellspacing="0"  class="table1"  border="0">
<tr valign="middle" align="left"><td width="15" height="10"></td><td></td></tr>
<tr valign="middle" align="left">
<td width="15"></td>
<td><font  color="White">input1</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<td width="15"></td>
<td>
<font color="Red"><input type="file" name="file" size="42"><br></font><font color="White">or paste below:</font><br>
<textarea name="sequence1" cols="96" rows="7"></textarea><br>     
</font>&nbsp;&nbsp;&nbsp;&nbsp;
</td>
</tr>
</table> </form>

输入1

或在下面粘贴:

类似地,在PHP页面中,我可以成功地将上传的文件从html页面传输到变量,并运行shell脚本,但无法处理textbox中的内容

<?php
$a = $_FILES['file']['tmp_name'];
$c = (isset($_POST['sequence1'])) ? $_POST['sequence1'] : false;
if($a!=NULL)
{
$output=shell_exec("sh server.sh $a");
 }
elseif ($c!=NULL){
$output=shell_exec("sh server.sh $c");}
else{
echo "No input";}
?>


有人能帮我解决这个问题吗?或者你能帮我的其他方法是将文本输入变量转换为shell脚本文件,解析php代码中的错误

  echo No input;
应该是

echo "No input";

如果我很了解你,这就是你需要做的:

<?php
if(isset($_POST['sequence1'])){
    //get the input content
    $textInput = $_POST['sequence1'];
    //temp file name
    $file = 'temp.txt';
    // Write the contents back to the file
    file_put_contents($file, $textInput);
    $output=shell_exec("sh server.sh $file");
}else{
    echo "No input";
}
?>


至少您的表单标记没有关闭
$a
需要在
isset()上进行三元赋值。如果不使用
'
将其封装为字符串,则无法回显
无输入。
是的,反正谁需要CSS。@VladNikitin:我已经给出了表单的一部分,因此它没有出现。我已经以原始表单将其关闭。@Ohgodwhy:我试图给出三元赋值isset(),但在代码方面并没有真正帮助我!!…进行了一些小的更改,但这不起作用!!…因为我编写的shell脚本以文件名为参数。!!当我通过html表单上载文件时,它们是完全没有任何问题的进程。但是,当我在表单的文本框中粘贴相同的数据时,它不会给我任何提示输出。我理解的最可能的原因是我编写的shell脚本将参数作为文件名,而不是直接作为文本。实际上,我需要帮助将此textinput存储在临时文件中并提供给shell脚本!!…我希望这会让您明白!!我已经尝试过,但shell脚本没有接受它。可能是需要的路径被定义。我尝试回显$file,它给出了temp.txt,这意味着文本进入了该文件,但shell脚本无法找到该文件的路径以将其作为一个文件input@RamT要检查的内容,请确保a)
temp.txt
与内容一起创建b)确保
server.sh
temp.txt
是在同一个目录c)中,您可以将命令存储在一个变量中,
echo$cmd
d)如果完成了上述所有操作,请将命令直接复制并运行到服务器中