PHP download file with control speed limit

Jul-23-2014 in PHP No comments

PHP download file with control speed limit script helps you set the download speed of a file on your server. If you set a limitation for download rate of the file that user download from your site or you want to control the download speed of files for users.

You can set a limitation for faster download speed for registered members and a slower speed for user is guests.

download file with speed limit using php

 

So let’s get started:

Create a file in your root directory or any where you want. Here i create file download.php with this code paste.

The following code:

 

Code above is when you are reading the file, but it does not read the entire file at a time, which here it read “n” bytes at a time in a file reading loop. This “N” is kbps speed you are downloading the files.

In my example above the download speed limit is 20kb/s

You just need to call the function download_speed_file(“file name with extension”,”download speed”) with two parameters is:

$file is the name of the file that you want to give to the user by limited speed download.

$speed is the allowed Bandwidth to download a file.

We will use function header() to send to the user’s browser. then use the browser / user agent will download the files.

Add Your Comment