This article mainly introduces the php method for controlling the file download speed. The example analyzes the php file operation skills and has some reference value. For more information, see
This article mainly introduces the php method for controlling the file download speed. The example analyzes the php file operation skills and has some reference value. For more information, see
This article describes how php controls the file download speed. Share it with you for your reference. The specific implementation method is as follows:
<? Php/** 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: '. $ download_file. 'File does not exist! ') ;}?>
I hope this article will help you with php programming.
,