PHP Display Shell Command Output in a box in Real Time - javascript

I have the following code which asks for input then applies shell.sh $folderPath $bits $group2
And I would like to have a box where it displays the output of my script exactly how it would've looked if I ran in in a terminal.
How do I do that?
Below is my code.
<?php
if (isset($_GET['folderPath']) && !empty($_GET['folderPath']) && file_exists($_GET['folderPath'])
&& is_dir($_GET['folderPath']) && isset($_GET['bits']) && isset($_GET['group2'])) {
$folderPath = $_GET['folderPath'];
$bits = $_GET['bits'];
$group2 = $_GET['group2'];
$run = shell_exec("shell.sh $folderPath $bits $group2");
echo "shell.sh $folderPath $bits $group2";
var_dump($run);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<form action="">
<label for="folderPath">Folder Path:</label>
<input type="text" id="folderPath" name="folderPath">
<br></br>
<fieldset id="bits">
<p>Please Choose bits: </p>
<input type="radio" value="8bits" name="bits"> 8bits <br>
<input type="radio" value="16bits" name="bits"> 16bits <br>
</fieldset>
<br></br>
<fieldset id="audio-type">
<p>Please Choose Type: </p>
<input type="radio" value="C12" name="group2"> C12 <br>
<input type="radio" value="LR" name="group2"> LR <br>
</fieldset>
<input class = "submitButton" type="submit" value="Submit">
</body>
</html>

First of all, you need to send your form data somewhere. In your case, it is your same script.
<form method="GET" action="path/to/my/script.php">
Secondly, shell_exec() returns output of executed command. You already wrote the code.
$path = $_GET['folderPath'];
$bits = $_GET['bits'];
$group2 = $_GET['group2'];
$output = shell_exec("shell.sh $path $bits $group2");
Thirdly, display the output where you want.
<div><?php print $output; ?></div>

Related

how to print a data from input fields to hard copy? [duplicate]

This question already has answers here:
reading innerHTML of HTML form with VALUE attribute (& its value) of INPUT tags
(2 answers)
Closed 1 year ago.
I am creating a project and want to print data that I put in input field on to hard copy ...
How can I do that?
for example:
If I have a table with input fields and I will input data into the field using browser, now, as soon as I am done with input, I want to print that information. (CODE UNDER), I took this code from W3schools: When I press print button, it prints the webpage.. but it does not print the information that is given to it...
How can I do that>
Here my code:
<!DOCTYPE html>
<html>
<title>Print form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<body>
<form method="post" action="" id="myfrm">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname">
<br> Last name:<br>
<input type="text" name="lastname">
<br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
<p align="center"><input type="button" onclick="myPrint('myfrm')" value="print"></p>
<script>
function myPrint(myfrm) {
var printdata = document.getElementById(myfrm);
newwin = window.open("");
newwin.document.write(printdata.outerHTML);
newwin.print();
newwin.close();
}
</script>
</body>
</html>
'''
You are copying over the HTML, but not the field values, the code below will do the trick.
See that the input fields now have Id's and we copy them over right before newwin.print()
<!DOCTYPE html>
<html>
<title>Print form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<body>
<form method="post" action="" id="myfrm">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname" id="first">
<br> Last name:<br>
<input type="text" name="lastname" id="last">
<br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
<p align="center"><input type="button" onclick="myPrint('myfrm')" value="print"></p>
<script>
function myPrint(myfrm) {
var printdata = document.getElementById(myfrm);
newwin = window.open("");
newwin.document.write(printdata.outerHTML);
newwin.document.getElementById("first").value = document.getElementById("first").value;
newwin.document.getElementById("last").value = document.getElementById("last").value;
newwin.print();
newwin.close();
}
</script>
</body>
</html>

How to make a html tag id into php string

I'm now building up a project and it have some errors and I'm not able to find them so help me out.
I have created a html file name (name.html) and a php file name (result.php) I have added some of Java when we click on Submit button it will take us to the result.php and display the text on an image through php my coding is like this.
For (name.html)
<html>
<body>
<input type="text" id="name" name="myname" placeholder="E.g: abc">
<input type="button" id="next" name="submit">
</body>
</html>
For (result.php)
<? php
header("Content-type: image/jpeg");
$imgPath = 'image.jpg';
$image = imagecreatefromjpeg($imgPath);
$color = imagecolorallocate($image, 255, 255, 255);
$string = $_GET["name"];
$fontSize = 3;
$x = 115;
$y = 185;
imagestring($image, $fontSize, $x, $y, $string, $color);
imagejpeg($image);
?>
The problem is that when I'm clicking over submit button the Script take me to the page result.php and the text inside the Input tag is not being displayed.
This is the example of working one
name.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="result.php" method="get">
<input type="text" id="name" name="myname" placeholder="E.g: abc">
<input type="submit" value="Submit">
</form>
</body>
</html>
result.php
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(300, 100);
$text_color = imagecolorallocate($im, 233, 14, 91);
$string = $_GET["myname"];
imagestring($im, 20, 5, 5, $string, $text_color);
// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');
// Output the image
imagejpeg($im);
// Free up memory
imagedestroy($im);
?>
Here's a little fix:
<html>
<body>
<form method="GET" action="result.php">
<input type="text" id="name" name="myname" placeholder="E.g: abc">
<input type="submit" id="next" name="submit">
</form>
</body>
</html>

How do I validate CSV file format using onclick function?

How can I validate my CSV format and I am using "required" in my html form to validate null value. I try to use onclick function to validate using alert box but alert box not function after I add php code inside javascript. Below is my code. Can anyone suggest a solution to me?
<?php
require_once "lib/base.inc.php";
?>
<script>
function storeQueEmail(){
<?php
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
$record['contact_first'] = $data[0];
$record['contact_last'] = $data[1];
$record['contact_email'] = $data[2];
$record['subject'] = $_REQUEST['subject'];
$record['message'] = $_REQUEST['message'];
$record['status'] = 0;
$oAdminEmail->insertQueEmail($record);
}
} while ($data = fgetcsv($handle,1000,",","'"));
?>;
alert('jyfkyugu');
window.location.href="cronjob_sendemail.php";
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Import a CSV File with PHP & MySQL</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" >
Subject : <br/>
<input type="text" name="subject" id="subject" required/> <br/>
Choose your file: <br />
<input name="csv" type="file"id="csv" required/> <br/>
Content : <br/>
<textarea name="message" cols="50" rows="10" required></textarea><br/>
<input type="submit" name="submit" value="Submit" onclick="storeQueEmail()"/>
</form>
</body>
</html>

Getting form value from PHP in JQuery

I want to get a form input value from a php file to a javascript one, like this:
PHP file:
<html>
<head>
<meta charset = "UTF-8">
<title> Search Customer by Field </title>
<script type="text/javascript" src="../lib/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../src/search-by-invoice-no.js"></script>
<table id="results" border="1"></table>
</head>
<body>
<?php
if( isset($_GET["invoiceNo"]) && "" != $_GET["invoiceNo"])
{
}
else
{
?>
<form id = "form1">
Invoice Number <input id="invoice" name="invoiceNo" type="text" value="<?=isset($_GET['invoiceNo'])? $_GET['invoiceNo'] :""?>">
<br/>
<input id="submit_btn" type="submit">
</form>
<?php
}
?>
</body>
</html>
JS file:
$(document).ready(function() {
var invoiceNo = $('#invoice').val(); //Returns undefined
alert(invoiceNo);
//etc...
Why this behaviour? I tried saveral other methods but all of them failed.
Your if/else structure makes no sense. If $_GET['invoiceNo'] exists and isn't empty, then you do your if logic, so the form is never created. But then, in your form, you check to see if $_GET['invoiceNo'] exists. It never will, except if it's empty, so what's the point of using it there?
You have a couple errors: inverted if/else is the reason you are not getting a value and among other things you are missing a parenthesis on your php output inside the input and input elements should end with />
<html>
<head>
<meta charset = "UTF-8">
<title> Search Customer by Field </title>
<script type="text/javascript" src="../lib/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../src/search-by-invoice-no.js"></script>
</head>
<body>
<?php
if( isset($_GET["invoiceNo"]) && "" != $_GET["invoiceNo"])
{ ?>
<form id = "form1" action='mypage.php' method='GET'>
Invoice Number <input id="invoice" name="invoiceNo" type="text" value="<?php echo (isset($_GET['invoiceNo']))? $_GET['invoiceNo'] :""; ?>" />
<br/>
<input id="submit_btn" type="submit" />
</form>
<?php
}
else
{
?>
<p>No value received</p>
<input id="invoice" name="invoiceNo" type="hidden" value="0" />
<?php
}
?>
</body>
</html>
Also, you don't even need to check if it is set as you already do, so something like
Invoice Number <input id="invoice" name="invoiceNo" type="text" value="<?php echo $_GET['invoiceNo']; ?>" />
Will work fine too
EDIT
<html>
<head>
<meta charset = "UTF-8">
<title> Search Customer by Field </title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
$(document).ready(function(){
var invoice = $('#invoice').val();
if(invoice == 0)
{
alert('No value was passed');
}
else
{
alert(invoice);
}
});
</script>
</head>
<body>
<?php
if( isset($_GET["invoiceNo"]) && "" != $_GET["invoiceNo"])
{ ?>
<form id = "form1" action='mypage.php' method='GET'>
Invoice Number <input id="invoice" name="invoiceNo" type="text" value="<?php echo $_GET['invoiceNo']; ?>" />
<br/>
<input id="submit_btn" type="submit" />
</form>
<?php
}
else
{
?>
<p>No value received</p>
<input id="invoice" name="invoiceNo" type="hidden" value="0" />
<?php
}
?>
</body>
</html>

Converting data with commas to variables in JavaScript

I have a row of a lines that is like this, these are the lines of html output of a php code that comes from a search.
here is the browser output page source (not the server source)
**<!DOCTYPE html>
<html>
<head>
<meta`enter code here` content="text/html; charset=windows-1252" http-equiv="content-type">
<title>my page</title>
</head>
<body>
<div style="text-align: center;">
<title>My Page</title>
<form name="myform" action="systemmonitor.php" method="GET">
<div align="center">My page<br>
<br>
<input name="sea1" placeholder="customtext" size="25" type="text"> <br>
<br>
<input name="sea2" placeholder="customtext" size="25" type="text"> <br>
<br>
<input name="sea" value="submit" type="submit"><br>
<br>
data00,data01,data02,data03, , , and so on
data10,data11,data12,data13, , , and so on
data20,data21,data22,data23, , , and so on
(and so on in rows)
<br>
</div>
</form>
</div>
</body>
</html>
here is the browser server source (php)
**<!DOCTYPE html>
<html>
<head>
<meta`enter code here` content="text/html; charset=windows-1252" http-equiv="content-type">
<title>my page</title>
</head>
<body>
<div style="text-align: center;">
<title>My Page</title>
<form name="myform" action="systemmonitor.php" method="GET">
<div align="center">My page<br>
<br>
<input name="sea1" placeholder="customtext" size="25" type="text"> <br>
<br>
<input name="sea2" placeholder="customtext" size="25" type="text"> <br>
<br>
<input name="sea" value="submit" type="submit"><br>
<br>
<?php
$searchthis = $_GET["sea1"];
$matches = array();
$handle = #fopen("sources.csv", "r");
if ($handle)
{
while (!feof($handle))
{
$buffer = fgets($handle);
if(strpos($buffer, $searchthis) !== FALSE)
$matches[] = $buffer;
}
fclose($handle);
}
//show results:
$myString = implode( ', ', $matches );
print_r($myString);
?><br>
<br>
</div>
</form>
</div>
</body>
</html>
Now, in the real page where is data0,data1,data2... is a php code that make this stuff from the html forms above, now the php output i dont what to see as is, but i want to convert to variables, and show only the variables where i want to, something likes this its ok:
var parsed[0][0]=data00;
var parsed[0][1]=data01;
var parsed[0][2]=data02;
var parsed[0][3]=data03;
var parsed[1][0]=data10;
0,X (X is the number of the colume)
1,X (X is the number of the row)
and then i show only the data where I want.
for example i will put this code somewhere in the page:
document.write(parsed[0][3]);
the data00 data01 is just a custom data that php will make from before.
how I can do this convert?
Is this what you want?
// the string containing the data
var externalData = 'one, two, three\n'
+ 'four, five, six\n'
+ 'seven, eight, nine';
// split the string into rows, and split each row into cells
var parsed = externalData.split('\n').map(function(row) {
return row.split(', ');
});
console.log(parsed[0][1]); // 'two'

Categories

Resources