これは、コールバックが C でどのように見えるかです:
typedef int (*curl_progress_callback)(void *clientp,
double dltotal,
double dlnow,
double ultotal,
double ulnow);
おそらくPHPでは次のようになります
curl_progress_callback($clientp, $dltotal, $dlnow, $ultotal, $ulnow)
したがって、iframe に .php ファイルをロードする page.html があると仮定します。
PHP スクリプトでは、次の関数が必要になります。
curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, 'curl_progress_callback');
curl_setopt($curl, CURLOPT_BUFFERSIZE,64000);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
次のような出力が生成されます。
0
0.1
0.2
0.2
0.3
0.4
...
次に、iframeページに進行状況バーが表示されます
<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%;
}
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>
いくつかのサンプルコードに興味があるかもしれません