PHP limit file Download speed

Source: Internet
Author: User
  1. Local file that should is send to the client
  2. $local _file = ' test-file.zip ';
  3. filename that the user gets as default
  4. $download _file = ' your-download-name.zip ';
  5. Set the download rate limit (= 20,5 kb/s)
  6. $download _rate = 20.5;
  7. if (file_exists ($local _file) && is_file ($local _file)) {
  8. Send headers
  9. Header (' cache-control:private ');
  10. Header (' Content-type:application/octet-stream ');
  11. Header (' Content-length: '. FileSize ($local _file));
  12. Header (' content-disposition:filename= '. $download _file);
  13. Flush Content
  14. Flush ();
  15. Open File stream
  16. $file = fopen ($local _file, "R");
  17. while (!feof ($file)) {
  18. Send the current file part to the browser
  19. Print fread ($file, round ($download _rate * 1024));
  20. Flush the content to the browser
  21. Flush ();
  22. Sleep One second
  23. Sleep (1);
  24. }
  25. Close file stream
  26. Fclose ($file);
  27. }
  28. else {
  29. Die (' error:the file '. $local _file, ' does not exist! ');
  30. }
Copy Code
Download speed, PHP
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.