<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_66265"> <div class="blockcode"> <div id="code_M3z"><ol> <li><?php<li>// local file that should be send to the client<li>$local_file = 'test-file.zip';<li>// filename that the user gets as default<li>$download_file = 'your-download-name.zip';<li> <li>// set the download rate limit (=> 20,5 kb/s)</li> <li>$download_rate = 20.5; </li> <li>if(file_exists($local_file) && is_file($local_file)) {</li> <li> // send headers</li> <li> header('Cache-control: private');</li> <li> header('Content-Type: application/octet-stream'); </li> <li> header('Content-Length: '.filesize($local_file));</li> <li> header('Content-Disposition: filename='.$download_file);</li> <li> </li> <li> // flush content</li> <li> flush(); </li> <li> // open file stream</li> <li> $file = fopen($local_file, "r"); </li> <li> while(!feof($file)) {</li> <li> </li> <li> // send the current file part to the browser</li> <li> print fread($file, round($download_rate * 1024)); </li> <li> </li> <li> // flush the content to the browser</li> <li> flush();</li> <li> </li> <li> // sleep one second</li> <li> sleep(1); </li> <li> } </li> <li> </li> <li> // close file stream</li> <li> fclose($file);}</li> <li>else {</li> <li> die('Error: The file '.$local_file.' does not exist!');</li> <li>}</li> <li>?></li> </ol></div> <em onclick="copycode($('code_M3z'));">复制代码</em> </div> <br> </td></tr></table> <div class="ptg mbm mtn"> PHP</div> <div id="comment_66265" class="cm"> </div> <div id="post_rate_div_66265"></div> <br><br>