forked from php-curl-class/php-curl-class
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress_advanced.php
More file actions
30 lines (27 loc) · 850 Bytes
/
progress_advanced.php
File metadata and controls
30 lines (27 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
require '../src/Curl/Curl.php';
use \Curl\Curl;
$curl = new Curl();
$curl->progress(function($client, $download_size, $downloaded, $upload_size, $uploaded) {
if ($download_size === 0) {
return;
}
// Display a progress bar: xxx% [=======> ]
$progress_size = 40;
$fraction_downloaded = $downloaded / $download_size;
$dots = round($fraction_downloaded * $progress_size);
printf('%3.0f%% [', $fraction_downloaded * 100 );
$i = 0;
for ( ; $i < $dots - 1; $i++) {
echo '=';
}
echo '>';
for ( ; $i < $progress_size - 1; $i++) {
echo ' ';
}
echo ']' . "\r";
});
$curl->complete(function($instance) {
echo "\n" . 'download complete' . "\n";
});
$curl->download('https://php.net/distributions/manual/php_manual_en.html.gz', '/tmp/php_manual_en.html.gz');