Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(0);
- function download($url)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'callback');
- curl_setopt($ch, CURLOPT_NOPROGRESS, false);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
- $html = curl_exec($ch);
- curl_close($ch);
- return $html;
- }
- function callback($jembut,$download_size, $downloaded, $upload_size, $uploaded)
- {
- if( $downloaded != 0 ){
- show_status($downloaded, $download_size, 20);
- }
- }
- function show_status($done, $total, $size=30) {
- $total = str_replace("-", "", $total);
- static $start_time;
- if($done > $total) return;
- if(empty($start_time)) $start_time=time();
- $now = time();
- $perc=(double)($done/$total);
- $bar=floor($perc*$size);
- $status_bar="\r[";
- $status_bar.=str_repeat("=", $bar);
- if($bar<$size){
- $status_bar.=">";
- $status_bar.=str_repeat(" ", $size-$bar);
- } else {
- $status_bar.="=";
- }
- $disp=number_format($perc*100, 0);
- $status_bar.="] $disp% ".formatSizeUnits($done)." / ".formatSizeUnits($total);
- $rate = ($now-$start_time)/$done;
- $left = $total - $done;
- $eta = round($rate * $left, 2);
- $elapsed = $now - $start_time;
- $status_bar.= " Menunggu : ".number_format($eta)." detik. Time left : ".number_format($elapsed)." sec.";
- echo "$status_bar ";
- flush();
- if($done == $total) {
- echo "\n";
- }
- }
- function formatSizeUnits($bytes)
- {
- if ($bytes >= 1073741824)
- {
- $bytes = number_format($bytes / 1073741824, 2) . ' GB';
- }
- elseif ($bytes >= 1048576)
- {
- $bytes = number_format($bytes / 1048576, 2) . ' MB';
- }
- elseif ($bytes >= 1024)
- {
- $bytes = number_format($bytes / 1024, 2) . ' kB';
- }
- elseif ($bytes > 1)
- {
- $bytes = $bytes . ' bytes';
- }
- elseif ($bytes == 1)
- {
- $bytes = $bytes . ' byte';
- }
- else
- {
- $bytes = '0 bytes';
- }
- return $bytes;
- }
- download("http://google.com");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement