我有一个按钮。通过单击此按钮,ajax调用PHP脚本。 PHP将启动一个powershell脚本,该脚本将在服务器端创建一个.csv文件。
Ajax可以很好地工作,PHP也可以:.csv文件将被创建!
我的问题是,我需要获取html-input-field的输入数据,将此值保存到var,然后通过数据将其从ajax传递到PHP。在PHP中,我需要通过带有参数的shellexec()
启动PowerShell脚本。此参数必须是html-input-field的值。
要弄清楚:
Ajax -> PHP -> Powershell
这是我尝试过的:
ajax.js:
var argument = document.getElementById("inputvalue").value;
$.ajax({
method: "POST",
url: "path/to/script.php",
data: { argument: argument},
success: function() {
console.log("message sent!");
}
})
script.php:
<?php
$bar = $_POST['argument'];
Shell_Exec ('powershell.exe -executionpolicy bypass -NoProfile -Command "C:\path\to\ps.ps1 '"$bar"' "');
?>
ps.ps1:
param ( $var1 )
[System.Windows.Forms.MessageBox]::Show($var1,"Titel",0)