首頁 >後端開發 >php教程 >php控製檔下載速度

php控製檔下載速度

WBOY
WBOY原創
2016-07-25 08:43:15858瀏覽
  1. /* set here a limit of downloading rate (e.g. 10.20 Kb/s) */
  2. $download_rate = 10.20;
  3. $download_file = 'download-file.zip';
  4. $target_file = 'target-file.zip';
  5. if(file_exists($download_file)){
  6. /* headers */
  7. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  8. header('Cache-control: private');
  9. header('Content-Type: application/octet-stream');
  10. header('Content-Length: '.filesize($download_file));
  11. header('Content-Disposition: filename='.$target_file);
  12. /* flush content */
  13. flush();
  14. /* open file */
  15. $fh = @fopen($download_file, 'r');
  16. while(!feof($fh)){
  17. /* send only current part of the file to browser */
  18. print fread($fh, round($download_rate * 1024));
  19. /* flush the content to the browser */
  20. flush();
  21. /* sleep for 1 sec */
  22. sleep(1);
  23. }
  24. /* close file */
  25. @fclose($fh);
  26. }else{
  27. die('Fatal error: the '.$download_file.' file does not exist!');
  28. }
  29. ?>
复制代码

下載速度, php


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn