PHP Ajax Shell Exec() Progress

时光总嘲笑我的痴心妄想 提交于 2019-12-23 03:10:59

问题


What I'm trying to do is quite simple.

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

etc

The progress bar doesn't need to be accurate, more of a comfort to show something is happening.

I've read it can be done using jquery and php/ajax.. but I've no idea how. Anyone got a simple example I can try a work with ?

Thanks :)


回答1:


The simplest way is to use twitter bootstrap:
http://twitter.github.com/bootstrap/components.html#progress

This is the server side part:

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

for ajax you can use jQuery ajax methods like $.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!");
    }
}


来源:https://stackoverflow.com/questions/13251349/php-ajax-shell-exec-progress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!