Forum Moderators: coopster
I'm trying to provide download from FTP space through browser link (on page saved in public_html) so that the download is done through HTTP protocol
The link passes a variable to a php doc (HTTPalt.php) that retrieves a file from FTP space
<?php
$ftpStream = ftp_connect("ftp.server.com");
$loginResult = ftp_login($ftpStream, "$WAclientLogin", "$clientPswd");
if ($loginResult) {
$files_array = ftp_nlist($ftpStream, $dirFnls);
array_shift($files_array);
array_shift($files_array);
while (list(, $this_file) = each ($files_array)) {
echo "<a href='../../_ProjectFiles/HTTPalt.php?ProjRev=$this_file'><span class='bodyTextLG'>$this_file</span></a><br>";}}
ftp_quit($ftpStream);
?>
Contents of the HTTPalt.php:
<?php
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=$ProjRev");
header("Content-Length: ".filesize("../public_ftp/$ProjRev"));
readfile("../public_ftp/$ProjRev");
?>
it works, except that it screws up the file it downloads...
I got a feeling that it has something to do with screwing the headers on the downloaded file... but I don't know much about it anyway so it's just a guess. It basicly downloads it (in lightning speed) - that's why I'm assuming it's not doing much at all - and when I try to open the file, it errors out saying that it's corrupted
... any thoughts on what the problem might be?
take a look at this manual page, especially the comments, it might point you in the right direction
[php.net...]