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?
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?
Jump to PostThis might help, but relies on PHP 5.3 or newer.
Jump to PostNot sure you can do this, can you? curl progress is one thing (with callback function), but with a progress bar?
@divyakrishnan
I need a progress bar foe downlaoding a file from host serevr using CURL
You can try this
Not sure you can do this, can you? curl progress is one thing (with callback function), but with a progress bar?
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>";
?>
@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{
...
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.