单击按钮以 html 格式运行 PHP 脚本

问题描述 投票:0回答:2

我想在 html 中单击按钮时运行 php 脚本。我在这里看了很多帖子,但它们似乎不起作用。截至目前,我正在 here 尝试解决方案,但它不起作用。我不知道是什么导致了问题,但我知道它不是 php 文件。任何帮助表示赞赏。

php脚本:

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

html代码:

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

外壳脚本:

#!/bin/bash

raspistill --output /var/www/html/Camera/Photos/Image.jpg
php html button
2个回答
0
投票

如果您使用过这样的 html 表单...

<form action="script.php" method="post">
    <input type="submit" value="Open Script" name="btn">
</form>

必须将

script.php
php 文件放在同一目录中...

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

点击按钮后。如果显示

Button Click
那么你的php文件被调用并且问题出在你的php脚本中......


0
投票

试试这个:

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

脚本.php

if(isset($_REQUEST['btn']))
{
    echo 'Button is clicked';
    // you can your shell script here like: 
    // shell_exec("/var/www/html/Camera/CameraScript.sh");
}

点击按钮时,会显示上面的信息

© www.soinside.com 2019 - 2024. All rights reserved.