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. The 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 ' of the file to browser * /print fread ($fh, round ($download _rate * 1 024)); /* 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! ');}? >
Summary : The above is the entire content of this article, I hope to be able to help you learn.