2

I'm currently looking into a way of showing the file download status on a page. I know this isnt needed since the user usually has a download status in the browser, but I would like to keep the user on the page he is downloading from, as long as the download is lasting. To do that, the download status should match the status the file actually has (not a fake prograss bar). Maybe it will also display the speed the user is downloading at, and estimate the time it will take, depending on the current download rate.

Can this be done using PHP and Javascript? Or does it realy require Flash or Java?

Should not somewhere on the Server be an information about who is downloading what at what speed and how much?

Thank you for your help in advance.

2 Answers 2

2

Not really possible cross-browser, but have a look into http://markmail.org/message/kmrpk7w3h56tidxs#query:jquery%20ajax%20download%20progress+page:1+mid:kmrpk7w3h56tidxs+state:results for a pretty close effort. IE (as usual) is the main culprit for not playing ball.

Sign up to request clarification or add additional context in comments.

3 Comments

But I'm not sure if this is what I'm looking for... I thought the xhr just starts a request, and has nothing else to do with the rest that happens?
The Request (Xml Http Request / XHR) is available all through the request, so by polling the Content-length of the request headers at a regular time, you can work out how much has downloaded, how long it's taken, thus giving speed of download, and estimated completion time.
@Christian Romeni, I'm with you to remove the IE from the category Browser.
0

You can do it with two seperate php files, first file for downloading process. Like as:

$strtTime=time();
$download_rate=120;   //downloading rate  
    $fp = fopen($real, "r");
      flush();// Flush headers
    while (!feof($fp)) {   
     $downloaded=round($download_rate * 1024);
        echo fread($fp,$downloaded );
        ob_flush();
       flush(); 
        if (connection_aborted ()) {

     // unlink("yourtempFile.txt" ;
            exit;
        }

     $totalDw +=$downloaded;
     // file_put_contents("yourtempFile.txt", "downloaded: $totalDw ; StartTime:$strtTime");
          sleep(1);
    }
    fclose($fp);
   // unlink("yourtempFile.txt") ;

Second file would be used for reading yourtempFile.txt by Ajax continusly. Using Sessions and Cookies wouldn't be used because of starting print.

5 Comments

Notice: You can change data file name as users id or other methods for avoiding from multi downloads problems.
But in this case I woul limmit the download rate to 120kbps? There will be only two files per user and only max. 20 users in total, all having a username. so I wont have a problem with that...
You can delete sleep(1); line, then there will not be any restriction or limited download rate. Therefor download limit would be used for data writing periods. for example without any sleep() command, decreasing of $download_rate to 1, you would be able to record full progress of downloading. But notice that with huge files this writing proccess, may decrease server performance. Because of high writing times. You can set download rate due to your server performance, your need, users numbers,... It is depends on your practice.
ok, so this is more about writing stats to the tmp file then the actual download rate...
Yes. You can use this tmp file with any application (include flash, ajax, refreshing php page ...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.