Tom Groot
Tom Groot

Reputation: 1180

Echo strings when page is still downloading

Im trying to make a PHP downloader.

echo '<p>Downloading New Update</p>';
$newUpdate = file_get_contents('http://your-server.com/update.zip');
echo 'Done downloading';

When I run the script (saying the zip takes long to download), the page loads until its fully downloaded and then shows the Downloading New Update and Done downloading at the same time.

What I want is to show the Downloading New Update before its finished downloading. When it is, Done downloading has to appear.

How can I combine this script with Ajax, Jquery, Javascript, in order to create a more dynamic downloader?

Upvotes: 0

Views: 56

Answers (1)

Peter K
Peter K

Reputation: 1807

Simple flush might solve the task

echo '<p>Downloading New Update</p>';
flush();
$newUpdate = file_get_contents('http://your-server.com/update.zip');
echo 'Done downloading';

and you need to ensure this text is not inside the table. Then browser should use progressive rendering and text should really apper. The reason you need flush is that PHP doesn't actually send text from echo() to browser untill certain conditions are met, like script is finished or flush() is called explicitly

Upvotes: 1

Related Questions