简体   繁体   English

在 HTML 中发送 Shell 脚本

[英]Send Shell Script in HTML

I would like to send shell script using the code below.我想使用下面的代码发送 shell 脚本。 I have fieldsets and input fields within.我里面有字段集和输入字段。

For example, I would like to run something like shell.sh folderPath eightbits lr例如,我想运行类似shell.sh folderPath eightbits lr

How do I make something like that work when I click the submit button?当我单击提交按钮时,如何使类似的东西起作用?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Something</title>
</head>
<body>
    <header>
        <nav>
            <ul class="nav-links">
                <li><a href="">Home</a></li>
            </ul>
        </nav>
    </header>

    <form action="">
        <label for="folderPath">Folder Path:</label>
        <input type="text" id="folderPath" name="folderPath">
    <br></br>
        <fieldset id="khz">
            <p>Please Choose Bits: </p>
          <input type="radio" value="eightbits" name="group1"> 8 bits <br>
          <input type="radio" value="sixteenbits" name="group1"> 16 bits <br>
        </fieldset>
    <br></br>
        <fieldset id="audio-type">
            <p>Please Choose Type: </p>
          <input type="radio" value="ch12" name="group2"> CH12 <br>
          <input type="radio" value="lr" name="group2"> LR <br>
        </fieldset>
        <input type="submit" value="Submit">
</body>
</html>

This should help:这应该有助于:

<?php
    if (isset($_GET['folderPath']) && !empty($_GET['folderPath']) && isset($_GET['group1']) && isset($_GET['group2'])) {
        $run = shell_exec("shell.sh $_GET['folderPath'] $_GET['group1'] $_GET['group2']");
        var_dump($run);
    }
?>

Note you should also add some function to verify the folderPath .请注意,您还应该添加一些 function 来验证folderPath

This will do the same:这将做同样的事情:

<?php
    if (isset($_GET['folderPath']) && !empty($_GET['folderPath']) && isset($_GET['group1']) && isset($_GET['group2'])) {

        echo $_GET['folderPath'];
        echo "<br />\n";

        $folderPath = $_GET['folderPath'];
        $group1 = $_GET['group1'];
        $group2 = $_GET['group2'];

        echo $folderPath;
        echo "<br />\n";

        $run = shell_exec("shell.sh $folderPath $group1 $group2");
        var_dump($run);
    }
?>

Full sample:完整示例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Something</title>
</head>
<body>
    <header>
        <nav>
            <ul class="nav-links">
                <li><a href="">Home</a></li>
            </ul>
        </nav>
    </header>

    <form action="">
        <label for="folderPath">Folder Path:</label>
        <input type="text" id="folderPath" name="folderPath">
    <br></br>
        <fieldset id="khz">
            <p>Please Choose Bits: </p>
          <input type="radio" value="eightbits" name="group1"> 8 bits <br>
          <input type="radio" value="sixteenbits" name="group1"> 16 bits <br>
        </fieldset>
    <br></br>
        <fieldset id="audio-type">
            <p>Please Choose Type: </p>
          <input type="radio" value="ch12" name="group2"> CH12 <br>
          <input type="radio" value="lr" name="group2"> LR <br>
        </fieldset>
        <input type="submit" value="Submit">

<?php
    if (isset($_GET['folderPath']) && !empty($_GET['folderPath']) && isset($_GET['group1']) && isset($_GET['group2'])) {
        $run = shell_exec("shell.sh $_GET['folderPath'] $_GET['group1'] $_GET['group2']");
        var_dump($run);
    }
?>

</body>
</html>

Save this file as: testpage.php将此文件另存为:testpage.php

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

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