PHP Curl进度条(回调返回百分比) [英] PHP Curl progress bar (callback returning percentage)

查看:1417
本文介绍了PHP Curl进度条(回调返回百分比)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用

实施curl进度条。

  curl_setopt($ curl,CURLOPT_PROGRESSFUNCTION,'callback'); 

curl_setopt($ curl,CURLOPT_BUFFERSIZE,64000);

curl_setopt($ curl,CURLOPT_FOLLOWLOCATION,true);

和回调函数。



是,脚本每次都在我的html上输出百分比,如下:

  0 
0.1
0.2
0.2
0.3
0.4
..
..
..
1
1.1



如何将此与CSS结合以显示更改的进度条?

解决方案

假设您有一个进度条HTML:

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

CSS:

 code>#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%;
}

和JavaScript:

  var progressElement = document.getElementById('progress')

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



您可以让它输出JavaScript并让它为您更新进度条,例如:

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

请注意,在分隔脚本块中,因为浏览器将尝试在执行之前读取完整脚本,并且进度栏将不起作用。


I have implemented the curl progress bar using

curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, 'callback');

curl_setopt($curl, CURLOPT_BUFFERSIZE,64000);

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

and a callback function.

problem is, the script is outputting the percentage on my html everytime like this :

0
0.1
0.2
0.2
0.3
0.4
..
..
..
1
1.1

How do i combine this with CSS to show a changing progress bar ?

解决方案

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.

这篇关于PHP Curl进度条(回调返回百分比)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆