Bootstrap progress bar in php
php, progress-bar, twitter-bootstrap
Solution
A way to do this and demonstrated here in a very simple format by jQuery;
You will send a AJAX request to your PHP page that has the command, the PHP page will return a `json_encode(array('success'=>true));` and when that's received and accepted, the progressbar updates and the next function will start loading.
I haven't tested this, and it's very rough, but it shows you (in a simple way) a technique that you could use.
$.getJSON('linkToLinuxCommand1.php').done(function(data) {
if (data.success === true) {
$('.progress').css('width', '25%');
$.getJSON('linkToLinuxCommand2.php').done(function(data) {
if (data.success === true) {
$('.progress').css('width', '50%');
$.getJSON('linkToLinuxCommand3.php').done(function(data) {
if (data.success === true) {
$('.progress').css('width', '75%');
$.getJSON('linkToLinuxCommand4.php').done(function(data) {
if (data.success === true) {
$('.progress').css('width', '100%');
alert('Done!');
}
});
}
});
}
});
}
});
Some remarks;
- As long as the Linux commands don't talk back to PHP, you only can get the `done` status of the PHP page
- Maybe you need to add more parameters to the `getJSON` request
- I'm not sure if JSON returns a boolean `true` or `false`, so maybe you need to check like a string; `data.success === "true"`
- Keep checking what `data` returns (after you setup your PHP page for returning JSON), using `console.log(data)`
- You might want to bind these functions to a trigger, such as `$('#button').click(function() {/* PLACE HERE */});` and place everything in a recursive function
Problem
I have got a webpage with some html and php. The php is there to execute some linux commands. I want to put a bootstrap progress bar into my webpage that progresses when the next linux command has been executed. Let's say I execute 4 linux commands, each time a command has finished executing, the progress bar should progress 25% further. I have searched the web but I couldn't find anything to what I need. Any suggestions? Only got the php/html part so far: ``` function progressbarStatus($width) { echo " <div class = 'container'> <div class = 'progress progress-striped active'> <div class = 'progress-bar' role = 'progressbar' aria-valuenow = '$width' aria-valuemin = '0' aria-valuemax = '100'style = 'width: $width%'></div> </div> </div> </div> "; } ```