Hi all,
I'm trying to make a PHP script that downloads a file off a remote FTP server and serves the file to the visitor with a limited download speed.
Right now I'm using fopen like this:
$path = "ftp://".$username.":".$password."@".$server."/";
$fullPath = ($path.$fileName);
$speed = 400; // 400 kb/s download rate
header("Cache-control: private");
header("Content-Type: application/octet-stream");
//header("Content-Length: ".filesize($fullPath));
header("Content-Disposition: filename=\"".$fileName."\"");
flush();
$fd = fopen($fullPath, "r");
while(!feof($fd)) {
echo fread($fd, round($speed*1024));
flush();
sleep(1);
}
fclose ($fd);
The file does download but with the wrong speed (8kb/s), does anyone know why?
When I run the same code with a local file instead of a file on FTP it works fine and downloads at the speed I set it to..
Thanks