Download Status with PHP and JavaScript

前端 未结 2 2029
我寻月下人不归
我寻月下人不归 2021-01-15 07:12

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 w

相关标签:
2条回答
  • 2021-01-15 07:19

    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.

    0 讨论(0)
  • 2021-01-15 07:31

    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.

    0 讨论(0)
提交回复
热议问题