In PHP file download will take advantage of the header fopen fread three main functions, while there are some auxiliary functions such as determining the existence of the file file_exists is_file, such as functions, let's look at a file download can limit the download speed instance
In PHP tutorial file download will take advantage of the header fopen fread three main functions, while there are some auxiliary functions such as determining the existence of the file file_exists Is_file, and so on, let's look at a file download can limit the download speed instance
*/
$file = "Test.mp3"; File to BES send to the client
$speed = 8.5; 8,5 kb/s Download Rate limit
if (file_exists ($file) && is_file ($file)) {
Header ("Cache-control:private");
Header ("Content-type:application/octet-stream");
Header ("Content-length:". FileSize ($file));
Header ("Content-disposition:filename= $file". "%20");
Flush ();
$FD = fopen ($file, "R");
while (!feof ($FD)) {
Echo fread ($FD, round ($speed *1024));
Flush ();
Sleep (1);
}
Fclose ($FD);
}
/*
Flush
Flush function Refreshes PHP program's buffering implementation echo dynamic output
The result of this function is that the page continually displays the data of the Echo output
for ($i =10; $i >0; $i--)
{
echo $i. '
';
Ob_flush ();
Flush ();
Sleep (1);
}
Ob_end_flush ();
Sleep
The sleep () function delays code execution for several seconds.
Header
The header () function sends the original HTTP header to the client.
It is important to recognize that the header () function must be called before any actual output is sent (in PHP 4 and later, you can use output caching to resolve this issue):
FileSize Get File size
Fread read the contents of a file opened by fopen
http://www.bkjia.com/PHPjc/444821.html www.bkjia.com true http://www.bkjia.com/PHPjc/444821.html techarticle in php file download will take advantage of the header fopen fread three main functions, while there are some auxiliary functions such as determining the existence of the file file_exists is_file, such as functions, let's look at a file ...