PHP: how to limit the file download speed

Source: Internet
Author: User
Tags php download
The download system should be used by many people. It is a very simple PHP application. However, when talking about PHP speed-limit download, it is estimated that some people are confused. In fact, this is also very simple. Below is a simple PHP download function combined with a limited speed to provide a piece of code. I hope it will be helpful for beginners: local file $ local_file

The download system should be used by many people. It is a very simple PHP application. However, when talking about PHP speed-limit download, it is estimated that some people are confused. In fact, this is also very simple. Below is a simple PHP download function combined with a limited speed to provide a piece of code. I hope it will be helpful for beginners: // local file $ local_file =

The download system should be used by many people. It is a very simple PHP application. However, when talking about PHP speed-limit download, it is estimated that some people are confused. In fact, this is also very simple. Below is a simple PHP download function combined with a limited speed to provide a piece of code. I hope it will be helpful to beginners:

// Local file $ local_file = 'test-file.zip '; // download is the default name $ download_file = 'your-download-name.zip'; // The download speed is limited to 5kb/s $ download_rate = 20.5; // check whether the file exists and ensure that the file is valid if (file_exists ($ local_file) & is_file ($ local_file) {// send the header ID header ('cache-control: private '); header ('content-Type: application/octet-stream'); header ('content-Length :'. filesize ($ local_file); header ('content-Disposition: filename = '. $ down Load_file); // refresh the output buffer flush (); // open the file $ file = fopen ($ local_file, "r"); while (! Feof ($ file) {// send the file print fread ($ file, round ($ download_rate * 1024); // buffer to the browser flush (); // pause 1 second execution sleep (1);} // close the file stream fclose ($ file);} else {die ('error: file --'. $ local_file. 'does not exist! ');}

Reprinted Please note: IT passers-by» PHP: how to limit the file download speed

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.