Input from textbox and file in PHP form

I have tried making a html and php page for taking input and processing them respectively. In the HTML page, user is given a option of either give a text or upload the file.

<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>

Similarly in the PHP page, i could succesfuly transfer the uploaded file from the html page to a varible and run the shell script but unable to process the content from 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";}
?>

Can anybody help me to solve this problem or other way you could help me would be text input variable to converted to a file for the shell script

Answers


If I understand you well, this is what you need to do:

<?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";
}
?>

Parse error in your php code.

  echo No input;

It should be

echo "No input";

Need Your Help