The php file is in web site directory (/var/www
) and I would like to execute it from index.html
which is in the same directory.
The php file:
<?php
exec("sudo -u pi /home/pi/camcv/camcv .. ");
?>
Can be run by typing php /var/www/script.php
in command line from anywhere in the system, it executes properly (camera flashes, opens the window with picture, no errors). I would need it to be executable by www-data
user from website.
I know there are many options, I have tried submit
forms, onClick
actions, sending a parameter ( $_POST['xy']
) then watching it with "if" structure in php file, AJAX
in form of XMLHttpRequest
and in form of $.ajax
, I tried to include javascript jquery.min.js
and have tried to add permissions in sudoers
or changed ownership of folders/files with allowing to read/write/execute... all without achieving the goal.
So my questions are:
-Does someone have a bulletproof way to make this work ?
-Can you tell me what exactly do I have to add in sudoers
?
Thanks for any advice.
PS: Few of the tries did redirect me to page http://(ip)/script.php
so there is at least some response from the buttons. Also, XMLHttpRequest did work on Changing the text on webpage (reading and posting txt file).
PSS: The function does not require any return information, I would need the page to stay on the site with the button, possibly not reloading.