Home » Php » execute Bash script on form submission through browser in php

execute Bash script on form submission through browser in php

Posted by: admin October 26, 2017 Leave a comment

Questions:

I am trying to execute bash command(to open an application in system) via a browser in php.

(Example) If I run the command in terminal it opens up Shotwell(image viewer) and displays the image.

I want to display image using shotwell in my system when I submit my form. How do I do this?

Here is my code. Why doesn’t it work?

form.php

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST"){
 if(isset($_POST['submit']))
 {
        exec('shotwell bike.jpg');
 }
}
?>
<html>
<body>
<form  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method=post>
  Store ID:<br>
  <input type="text" name="username" required>
  <br>
  Department ID:<br>
  <input type="text" name="emailID" required>
  <br><br>
  <input type="submit" name="submit" value="Submit">
</form>

</body>
Answers: