'Run PHP script in html on button click

I want to run a php script on a button click in html. I've looked at a lot of the posts here, but they don't seem to work. As of now, I'm trying the solution here, but it doesn't work. I have no idea what's causing the trouble, but I know that it isn't the php file. Any help is appreciated.

php script:

<?php
shell_exec("/var/www/html/Camera/CameraScript.sh");
header('Location: /Camera/Camera.html?success=true');
?>

html code:

<form action="Script.php">
        <input type="submit" value="Open Script">
</form>

Shell Script:

#!/bin/bash

raspistill --output /var/www/html/Camera/Photos/Image.jpg


Solution 1:[1]

If you have use html form like this...

<form action="script.php" method="post">
    <input type="submit" value="Open Script" name="btn">
</form>

it's must require put script.php php file in same directory...

<?php
 echo "Button Click";
 shell_exec("/var/www/html/Camera/CameraScript.sh");
 header('Location: /Camera/Camera.html?success=true');
?>

After click on button. if display Button Click then your php file is call and problems is in your php script...

Solution 2:[2]

Try this:

<form action="script.php">
    <input type="submit" value="Open Script" name="btn">
</form>

script.php

if(isset($_REQUEST['btn']))
{
    echo 'Button is clicked';
    // you can your shell script here like: 
    // shell_exec("/var/www/html/Camera/CameraScript.sh");
}

When button is clicked, then the above message is display

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pravin Vavadiya
Solution 2