Home >Backend Development >PHP Tutorial >php control file download speed

php control file download speed

WBOY
WBOYOriginal
2016-07-25 08:43:15858browse
  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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn