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.
php文件位于网站目录(/ var / www)中,我想从index.html执行它,它位于同一目录下。
The php file:
php文件:
<?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.
可以通过从系统中的任何位置在命令行输入php /var/www/script.php来运行,它可以正常执行(相机闪烁,打开带有图片的窗口,没有错误)。我需要它来自网站的www-data用户可执行。
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.
我知道有很多选项,我已经尝试过提交表单,onClick动作,发送参数($ _POST ['xy'])然后用php文件中的“if”结构,XMLHttpRequest形式的AJAX以及$的形式观看它.ajax,我试图包含javascript jquery.min.js,并尝试在sudoers中添加权限或更改文件夹/文件的所有权,允许读/写/执行...所有都没有达到目标。
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
?
- 你能告诉我在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).
PS:几乎没有尝试将我重定向到页面http://(ip)/script.php所以至少有一些来自按钮的响应。此外,XMLHttpRequest确实可以更改网页上的文本(阅读和发布txt文件)。
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.
PSS:该功能不需要任何返回信息,我需要页面留在网站上的按钮,可能没有重新加载。
1 个解决方案
#1
0
try to resolve this problem with jQuery:
尝试用jQuery解决这个问题:
<!doctype html><head><meta charset="utf-8"></head><body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(function(){
$("#clickme").bind('click', function(){
$.get( "script.php", function( data ) {
$( ".result" ).append( data );
});
});
});
</script>
<input type="submit" id="clickme" value="TEST">
<div class="result">Result...</div>
</body>
</html>
if your "script.php" has any response you will get it in the div container
如果您的“script.php”有任何响应,您将在div容器中获取它
#1
0
try to resolve this problem with jQuery:
尝试用jQuery解决这个问题:
<!doctype html><head><meta charset="utf-8"></head><body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(function(){
$("#clickme").bind('click', function(){
$.get( "script.php", function( data ) {
$( ".result" ).append( data );
});
});
});
</script>
<input type="submit" id="clickme" value="TEST">
<div class="result">Result...</div>
</body>
</html>
if your "script.php" has any response you will get it in the div container
如果您的“script.php”有任何响应,您将在div容器中获取它