Reputation: 753
I have written a very simple Hello World script as a bash file and saved it on my desktop.
I want to execute this file when a Submit button is pressed.
The following script works fine and I see the Hello World on the firefox webbrowser:
<?php
echo shell_exec('sh /home/administrator/Desktop/Helloworld.sh');
?>
However the following script does not give me any result:
<!DOCTYPE html>
<html>
<body>
<?php
if (isset($_POST['Submit1'])) {
echo shell_exec('sh /home/administrator/Desktop/Helloworld.sh');
}
?>
<Input Type = "Submit" Name ="Submit1" Value = "Save Parameters">
</body>
</html>
Any idea why? I don't get any errors in my log file.
Upvotes: 0
Views: 3344
Reputation: 98921
You are not posting anything, for that you'll need a form, i.e.:
file.php
<html>
<body>
<?php
if (isset($_POST['Submit1'])) {
echo shell_exec('sh /home/administrator/Desktop/Helloworld.sh');
}
?>
<form action="file.php" method="post">
<input Name= "Submit1" type="submit">
</form>
</body>
</html>
Also, make sure the file /home/administrator/Desktop/Helloworld.sh
is executable, i.e.:
chmod +x /home/administrator/Desktop/Helloworld.sh
Upvotes: 2