Main Menu
(Move to ...)
Home
About Me
Contact
▼
Pages
(Move to ...)
Home
▼
Friday, February 08, 2013
File download with rename and speed limit
I have seen some site provide download limit when download a file from the site. From this technique I am inspire to write the function. This function allow download file with rename and download speed limit.
20,5 kb/s) * * @param string $local_file * @param string $download_file * @param float $download_rate */ function downloadFileWithSpeedLimit($local_file, $download_file, $download_rate ){ if(file_exists($local_file) && is_file($local_file)) { // send headers header('Cache-control: private'); header('Content-Type: application/octet-stream'); header('Content-Length: '.filesize($local_file)); header('Content-Disposition: filename='.$download_file); // flush content flush(); // open file stream $file = fopen($local_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 one second sleep(1); } // close file stream fclose($file); } else { die('Error: The file '.$local_file.' does not exist!'); } } ?>
‹
›
Home
View web version