Limiter le débit d’un fichier en upload
Publié le 26 juillet 2015 | Par adminblog | Commenter
Utilitaire pour limiter la bande passante …
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php // filename that the user gets for downloading $download_file = 'file-to-download.zip'; // set the download rate limit $download_rate = 20.5; //=> 20,5 kb/s header('Cache-control: private'); header('Content-Type: application/octet-stream'); header('Content-Length: '.filesize($download_file)); header('Content-Disposition: filename='.$download_file); flush(); // open file stream $file = fopen($download_file, "r"); while(!feof($file)) { // send the current file part to the browser print fread($file, round($download_rate * 1024)); // flush the content to the browser flush(); sleep(1); } fclose($file);} ?> |
Commentaires récents