PHPドロップダウンメニューはパラメータを使用してスクリプトを実行します。

PHPドロップダウンメニューはパラメータを使用してスクリプトを実行します。

このように実行するシェルスクリプトがあります

/var/www/test.sh 2015

または

/var/www/test.sh 2014

このスクリプトが実行されると、実際にfreeradiusからデータを取得し、wwwフォルダの特定の年のgnuplotデフォルトプロットを生成します。

/var/www/output.jpg 

それでは、2015年、2014年などを含むPHPドロップダウンメニューを作成したいと思います。ユーザーが年を選択した場合は、選択した特定の年でスクリプトを実行する必要があります。しかし、どのように年をシェルスクリプトに渡すことができますか?

これまでこれを試しましたが、うまくいきません。

root@rm:/var/www# cat test5.php

<html>
<head><title>some title</title></head>
<body>
  <form method="post" action="">
    <input type="text" name="something" value="<?= isset($_POST['something']) ? htmlspecialchars($_POST['something']) : '' ?>" />
    <input type="submit" name="submit" />
  </form>

<?php
if(isset($_POST['submit'])) {
echo ($_POST['something']);
// Now the script should be executed with the selected year 
      $message=shell_exec("/var/www/test.sh $something");
// and after executing the script, this page should also open the output.jpg in the browser

}
?>
</body>
<html>
root@rm:/var/www#

ベストアンサー1

HTMLのドロップダウンメニューはオプションです。

<form method="post" action="">
    <select name="something">
        <option value="2014">year 2014</option>
        <option value="2015">year 2015</option>
    </select>
    <input type="submit" name="submit" />
</form>

それから提出後

$something = $_POST["something"];
shell_exec("/var/www/test.sh $something");

おすすめ記事