How PHP controls File download speed
This article mainly introduces the PHP control file download Speed method, the example analysis of PHP operation file skills, with a certain reference value, the need for friends can refer to the next
This article explains how PHP controls how fast files are downloaded. Share to everyone for your reference. The implementation method is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23 24 25 26 27 28 29 30 31 32 |
/* * Set here a limit of downloading rate (e.g. 10.20 kb/s) */ $download _rate = 10.20; $download _file = ' download-file.zip '; $target _file = ' target-file.zip '; if (file_exists ($download _file)) { /* Headers */ Header (' last-modified: '. Gmdate (' d, D M Y h:i:s '). ' GMT '); Header (' cache-control:private '); Header (' Content-type:application/octet-stream '); Header (' Content-length: '. FileSize ($download _file)); Header (' content-disposition:filename= '. $target _file); /* Flush Content */ Flush (); /* Open File */ $fh = @fopen ($download _file, ' R '); while (!feof ($FH)) { /* Send only current part of the file to browser */ Print fread ($fh, round ($download _rate * 1024)); /* Flush the content to the browser */ Flush (); /* Sleep for 1 sec */ Sleep (1); } /* Close File */ @fclose ($FH); }else{ Die (' Fatal error:the '. $download _file. ' File does not exist! '); } ?> |
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/973122.html www.bkjia.com true http://www.bkjia.com/PHPjc/973122.html techarticle php Control File Download Speed method This article mainly introduces the PHP control file download Speed method, the example analysis of PHP operation file skills, with a certain reference value, the need for friends ...