1
<?php
$zip_file="test.zip";
$source="abc.com/$zip_file";
$data=file_get_contents("$source");
sleep(1);
//display the progress
$dest=file_put_contents($zip_file,$data);
?>

<div id='status'>progress ...</div>

I want to show the progress bar for every 1 second of downloaded % and remaining % to download.

vijay kumar
  • 287
  • 2
  • 8
  • 28

1 Answers1

0

Your PHP is going to run server-side. In fact, depending on your server implementation, your PHP is probably going to finish running before your server is even willing to start writing a response based on your PHP's output. You cannot let the client view download progress purely through PHP or any server side code. You will have to implement a progress bar client side, by monitoring the progress of the the download.

Think of it like this: you want to monitor the client's receipt of data, but the PHP is running on your server. Your server has no idea how much data the client has received.

If the download you're talking about is literally the download of an entire new web page, per window.location = http://example.com/uri/for/your/php.php or a link or an HTML form, then you will not have any opportunity to display progress to your client. That will be totally up to the browser.

However, if the download takes place through an XMLHttpRequest (and most manual requests do, even jQuery I think) then you have some hope. You can learn about monitoring the progress of XMLHttpRequest downloads from this answered question.

Community
  • 1
  • 1
William Rosenbloom
  • 2,506
  • 1
  • 14
  • 37