【问题标题】:PHP Ajax Shell Exec() ProgressPHP Ajax Shell Exec() 进度
【发布时间】:2012-11-06 12:44:10
【问题描述】:

我要做的很简单。

echo "doing a...."
Start progress bar
then exec("commandA")
stop progress bar

echo "doing b...."
Start progress bar
then exec("commandA")
stop progress bar

echo "doing c...."
Start progress bar
then exec("commandC")
stop progress bar

进度条不需要准确,更多的是为了显示正在发生的事情。

我读过它可以使用 jquery 和 php/ajax 来完成。但我不知道怎么做。 任何人有一个简单的例子,我可以尝试一个工作?

谢谢:)

【问题讨论】:

  • 如果您不知道服务器端部分,请告诉我编辑我的答案

标签: php ajax exec progress


【解决方案1】:

最简单的方法是使用twitter bootstrap:
http://twitter.github.com/bootstrap/components.html#progress

这是服务器端部分:

$command = isset($_GET['command']) ? $_GET['command'] : null;
if ($command == null) {
    die("0");
}
echo (int) exec($command);

对于 ajax,您可以使用 jQuery ajax 方法,例如 $.get , $.post , $.ajax

$.get('exec.php', { command: 'commandA'}, function(response) {
    if(response == 1) {
        //and you can easily change the width of the progress bar with jQuery:
        $(".bar").css('width', '40%');
    } else {
        alert("The execution got an error!");
    }
}

【讨论】:

  • 感谢您的回复。我不确定如何使用它或如何将我的 exec() 调用添加到其中。对不起:(
  • @user1635970 我更新了答案并为您放置了服务器端示例。但请注意,这可能很危险,并且攻击者能够在您的服务器上运行有害命令。如果这是您的答案,请将其标记为已接受的答案以帮助其他人
  • 谢谢,这是有道理的。不知道这对我有什么用,因为我从命令中得到的结果不会给我任何有价值的东西。我应该更多地围绕请等待“工作”图像而不是进度条来表达我的问题!跨度>
  • 谢谢,我已经使用$.get('exec.php', { command: 'ls -l'}, function(response) { 进行了尝试,但返回“解析错误:语法错误,意外'。',期待 T_VARIABLE 或'$'”
  • 你需要硬编码 2>&1 在 commad 的末尾才能看到全通道输出
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-19
  • 1970-01-01
  • 2010-09-18
  • 2010-10-06
  • 2023-04-03
  • 2019-01-04
  • 1970-01-01
相关资源
最近更新 更多