diff options
author | Colin Smith <colin@pfsense.org> | 2005-04-11 15:50:25 +0000 |
---|---|---|
committer | Colin Smith <colin@pfsense.org> | 2005-04-11 15:50:25 +0000 |
commit | 131bb57602c94b6017a0662def73cdfeb6f9eae9 (patch) | |
tree | 70aa765fa0888668d1ca20b85ccb36c66b14abd7 /usr/local/www/guiconfig.inc | |
parent | cc4d4ebda20584ce72be6f9c4c2316935df6878c (diff) | |
download | pfsense-131bb57602c94b6017a0662def73cdfeb6f9eae9.zip pfsense-131bb57602c94b6017a0662def73cdfeb6f9eae9.tar.gz |
Move download/progress bar functions to guiconfig.inc - they'll be used in the package installer shortly.
Diffstat (limited to 'usr/local/www/guiconfig.inc')
-rwxr-xr-x | usr/local/www/guiconfig.inc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/usr/local/www/guiconfig.inc b/usr/local/www/guiconfig.inc index 07a1e28..ec01164 100755 --- a/usr/local/www/guiconfig.inc +++ b/usr/local/www/guiconfig.inc @@ -500,4 +500,68 @@ function update_if_changed($varname, & $orig, $new) { return false; } +function download_file_with_progress_bar($url_file, $destination_file) { + global $ch, $fout, $file_size, $downloaded, $counter; + $file_size = 1; + $downloaded = 1; + /* open destination file */ + $fout = fopen($destination_file, "wb"); + + /* + Originally by Author: Keyvan Minoukadeh + Modified by Scott Ullrich to return Content-Length size + */ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url_file); + curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); + curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body'); + curl_setopt($ch, CURLOPT_NOPROGRESS, '1'); + + curl_exec($ch); + fclose($fout); + return 1; + + if ($error = curl_error($ch)) { + return -1; + } +} + +function read_header($ch, $string) { + global $file_size, $ch, $fout; + $length = strlen($string); + ereg("(Content-Length:) (.*)", $string, $regs); + if($regs[2] <> "") { + $file_size = intval($regs[2]); + } + return $length; +} + +function read_body($ch, $string) { + global $fout, $file_size, $downloaded, $counter; + $length = strlen($string); + $downloaded += intval($length); + $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); + $downloadProgress = 100 - $downloadProgress; + /* + $a = $file_size; + $b = $downloaded; + $c = $downloadProgress; + $text = " Download Status\\n"; + $text .= "---------------------------------\\n"; + $text .= " File size : {$a}\\n"; + $text .= " Downloaded : {$b}\\n"; + $text .= " Percent : {$c}%\\n"; + $text .= "---------------------------------\\n"; + */ + $counter++; + if($counter > 150) { + $tostatus = $static_status . $downloadProgress; + update_status($tostatus); + update_progress_bar($downloadProgress); + $counter = 0; + } + fwrite($fout, $string); + return $length; +} ?> |