0

HI..

I need a progress bar foe downlaoding a file from host serevr using CURL
The downloaded script is working fine.
can anyone suggest code for a progress bar for curl downlaod?

4
Contributors
5
Replies
9
Views
4 Years
Discussion Span
Last Post by LastMitch
0

Not sure you can do this, can you? curl progress is one thing (with callback function), but with a progress bar?

Edited by diafol

0

Hi..

Thanks for your reply.
I used following code.
Its working well but it displaying the message "please wait..." repeatedly on the screen.
Is there any way to show the message only once when download progress.

<?php



  $url  = 'http://192.168.1.40/example/example.pdf';
  $path = 'example.pdf';
    $fp = fopen($path, 'w');






$ch = curl_init( $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt( $ch, CURLOPT_NOPROGRESS, false );

curl_setopt( $ch, CURLOPT_PROGRESSFUNCTION, 'progressCallback' );

curl_setopt( $ch, CURLOPT_FILE,  $fp );

curl_exec( $ch );
fclose($fp);



function progressCallback( $download_size, $downloaded_size, $upload_size, $uploaded_size )

{

echo "please wait...";
static $previousProgress = 0;

if ( $download_size == 0 )

$progress = 0;

else

$progress = round( $downloaded_size * 100 / $download_size );

if ( $progress > $previousProgress)

{


$previousProgress = $progress;

$fp = fopen( "example.pdf", 'a' );

fputs( $fp, "$progress\n" );

fclose( $fp );

}


}
echo "<script>window.location='completion.php'</script>";


?>
0

@divyakrishnan

Is there any way to show the message only once when download progress.

I think you can try to used if statement.

if ($progress){ 

echo "please wait...";

}else{

...

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.