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!

3

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, let me check it out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.