Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3851236
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:07:53+00:00 2026-05-19T17:07:53+00:00

I have a very simple and standard PHP force download script. How do I

  • 0

I have a very simple and standard PHP force download script.

How do I check if/when the download has completed in order to notify the user on the clientside? I don’t even need to show the progress in real time, I am only interested in the very specific event: “when the download completes”. Based on my research, it seems like it would have to be determined from the serverside as there is noondownloadready event and I don’t think it is possible to intercept browser events.

So it seems that my best bet would be to compare bytes sent to total bytes with some sort of clientside/severside interaction. How would I go about checking the bytes sent from the server for a PHP forced download? is there some sort of global PHP variable that store these data that I can ping with AJAX?

    <?php

    header("Content-Type: video/x-msvideo");
    header("Content-Disposition: attachment; filename=\"".basename($realpath)."\";");

    ...

    $chunksize = 1 * (1024 * 1024); // how many bytes per chunk
    if ($size > $chunksize) {
           $handle = fopen($realpath, 'rb');
           $buffer = '';
           while (!feof($handle)) {
                 $buffer = fread($handle, $chunksize);
                 echo $buffer;
                 ob_flush();
                 flush();
           }
          fclose($handle);
     }             
     else {
         readfile($realpath);
     }
     exit();
     ?>

The reason I need this:

For the project I am working on, it is required that after the download starts, the page redirects to (or displays) a “please wait while the download completes” page. Then, once it is complete, it should redirect to (or display) a “Your download is complete, thank you” page. I am open to other ideas that would achieve the same result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:07:54+00:00Added an answer on May 19, 2026 at 5:07 pm

    Check out this Sitepoint Forum Post that describes the solution.

    Basically, once the while loop breaks, you’re done!

    Here’s the full thread that describes using an AJAX poll to detect when the download is complete: http://www.sitepoint.com/forums/showthread.php?t=618233

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple bit of script that changes the status of an
I have finally created a very simple Hello World style PHP Extension dll on
i have very simple problem. I need to create model, that represent element of
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple problem which requires a very quick and simple solution
I have a very simple WPF application in which I am using data binding
I have a very simple TCP server written in C. It runs indefinitely, waiting
I have a very simple Java RMI Server that looks like the following: import
I have a very simple ASP.Net page that acts as a front end for
I have a very simple question. I want to test whether a particular port

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.