But I have a problem when the parameter in sleep is 1 the download speed stuck at 10kb. but when I change it to a number less then 1. the speed becomes unlimited.
I can't define the speed limit in any case. What can I do to overcome this problem.
My code:
Expand|Select|Wrap|Line Numbers
- <?php
- $fileName=$_GET['go'];
- $ftp="127.0.0.1";
- $user="Admin";
- $pass="12";
- $path="files/";
- $speed = 20000;
- $url="ftp://$user:$pass@$ftp/$path$fileName";
- if(file_exists($url) && is_file($url))
- {
- header('Content-Type: application/octet-stream');
- header('Content-Length: '.filesize($url));
- header('Content-Disposition: filename='.$fileName);
- flush();
- $file = fopen($url, "r");
- while(!feof($file)){
- echo fread($file, round($speed*1024));;
- flush();
- sleep(1);
- }
- fclose($file);
- }
- else {
- die('Error: The file '.$local_file.' does not exist!');
- }