Php controls file download speed
- /* 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! ');
- }
- ?>
|
Download speed, php