PHP Curl progress bar (callback returning percentage) PHP Curl progress bar (callback returning percentage) curl curl

PHP Curl progress bar (callback returning percentage)


Suppose you have a progress bar HTML:

<div id="progress-bar">    <div id="progress">0%</div></div>

CSS:

#progress-bar {    width: 200px;    padding: 2px;    border: 2px solid #aaa;    background: #fff;}#progress {    background: #000;    color: #fff;    overflow: hidden;    white-space: nowrap;    padding: 5px 0;    text-indent: 5px;    width: 0%;}

And JavaScript:

var progressElement = document.getElementById('progress')function updateProgress(percentage) {    progressElement.style.width = percentage + '%';    progressElement.innerHTML = percentage + '%';}

You can have it output JavaScript and have it update the progress bar for you, for example:

<script>updateProgress(0);</script><script>updateProgress(0.1);</script><script>updateProgress(0.2);</script>....

Note that you can't put each update in separate script block, because the browser will try to read the full script before executing and the progress bar will not work.