【发布时间】:2017-02-16 12:42:47
【问题描述】:
首先:我的网络编码技能几乎不存在,我只是在很久以前做过一点 HTML... 我今天才开始使用 php。
我的目标是:拥有一个颜色选择器并将选择的值作为参数发送到 python 脚本。
我设法使用了 jscolor 选择器库 (http://jscolor.com/examples/),并且我还能够使用来自 php 的 (color) 参数运行 python 脚本。
我现在的问题是:
如何将颜色字符串(hex-str)提交给执行命令(LED_color)?
<?php
$LED_color="FFFFFF";
$LED_color=escapeshellarg($LED_color);
if (isset($_POST['button']))
{
$LED_color = $_REQUEST['hex-str'];
echo shell_exec("sudo /home/pi/LEDscripts/color-by-arg.py $LED_color");
}
?>
<html>
<head>
<title>Basic usage</title>
</head>
<body>
<div style="position:absolute; left:280px; top:10px;">
toString = <span id="hex-str"></span><br />
</div>
<script src="jscolor.js"></script>
Color: <input class="jscolor {closable:true,closeText:'Close me!',onFineChange:'update(this)'}" value="000000">
<script>
function update(picker) {
document.getElementById('hex-str').innerHTML = picker.toString();
}
</script>
<form method="post">
<p>
<button name="button">Submit color</button>
</p>
</form>
</body>
</html>
【问题讨论】:
标签: php variables exec jscolor