1

I'm new to php and html (internet languages in general) and I would like to execute a python script that takes a picture from my php page.

I did some research, edited some code (according to my understanding) and came up with this, but it doens't do anything.

<!DOCTYPE html>
<html>
<head>
        <title>Test</title>
</head>
<body>
        <form action="" method="post">
                <button type="submit" name="sub" value="call">Click</button>
        </form>
</body>
</html>

<?php
if(isset($_POST['sub']))
{
        exec('sudo python take_picture.py');
        echo "Picture captured";
}
?>

I managed to execute the python script from a html page invoking a simple php script separately, but when it takes the picture it sends me to a new page (blank page with the text displayed) which I don't want. Here are the codes:

HTML button:

<form action="take_picture.php" method="post">
<button>Click</button>
</form>

PHP script:

<?php
exec('sudo python take_picture.py');
?>

What I need is to simply press the "click" button and take the picture without sending me to anywhere else.

Could you please guys aid me to achieve what I need and explain with apples what I was doing wrong or what I missed.

Thank you in advance!

Carlos Pérez
  • 47
  • 1
  • 1
  • 9
  • Possible duplicate of [How to call shell script from php that requires SUDO?](https://stackoverflow.com/questions/3166123/how-to-call-shell-script-from-php-that-requires-sudo) – Klaus D. Nov 02 '18 at 18:49
  • Nope, It is not because I actually achieved this just need to do it in a different way – Carlos Pérez Nov 02 '18 at 19:00
  • Possible duplicate of [Running a Python script from PHP](https://stackoverflow.com/questions/19735250/running-a-python-script-from-php) – Mohamed Shahid Nov 02 '18 at 20:39

1 Answers1

3

You can make an :

<?php 

$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);
echo $output;

?>

More information on this Stack Overflow Question.

Running a Python script from PHP