How do I download a file directly from FTP without having to temporarily download to the PHP server?
Code:
<?php//....$fcon=ftp_connect($ftp_host);$conecta=ftp_login($fcon,$ftp_username,$ftp_senha);ftp_pasv($fcon,true);ftp_chdir($fcon,$ftp_pasta);$arquivo=basename($arquivo_ftp);$arquivo_temp="../anexos/" . $arquivo;
ftp_get($fcon, $arquivo_temp, $arquivo, FTP_BINARY);
ftp_close($fcon);
//Prepara o arquivo para download no navegador
$file = $arquivo;
//Vê a extensão do arquivo
$type = filetype($arquivo_temp);
//Vê o tamanho do arquivo
$size = filesize($arquivo_temp);
//Seta o header da página para forçar o navegador a fazer download
header("Content-Description: File Transfer");
header("Content-Type:{$type}");
header("Content-Length:{$size}");
header("Content-Disposition: attachment; filename=\"" . $file . "\"");
//Faz download
readfile($arquivo_temp);
//Apaga o arquivo temporário
unlink($arquivo_temp);
As it is in the above code, the file needs to be fetched from FTP and temporarily downloaded to a server folder, and then sent to the user. With this files very large and the large amount of users is leaving the network slow.
How can I make it authenticate to FTP through PHP and make a direct download link between user and FTP?