简体   繁体   English

单击按钮时在 html 中运行 PHP 脚本

[英]Run PHP script in html on button click

I want to run a php script on a button click in html.我想在 html 中单击按钮时运行 php 脚本。 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.我不知道是什么导致了问题,但我知道这不是 php 文件。 Any help is appreciated.任何帮助表示赞赏。

php script: php脚本:

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

html code: html代码:

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

Shell Script:外壳脚本:

#!/bin/bash

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

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单击按钮时,将显示上述消息

If you have use html form like this...如果您使用这样的 html 表单...

<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...它必须要求将script.php php 文件放在同一目录中...

<?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...如果显示Button Click则您的 php 文件被调用,问题出在您的 php 脚本中...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM