Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

A story of a download that didn't work

4:23 am on Aug 8, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 16, 2004
votes: 0

now I'm stuck...

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

$ftpStream = ftp_connect("ftp.server.com");
$loginResult = ftp_login($ftpStream, "$WAclientLogin", "$clientPswd");
if ($loginResult) {
$files_array = ftp_nlist($ftpStream, $dirFnls);
while (list(, $this_file) = each ($files_array)) {
echo "<a href='../../_ProjectFiles/HTTPalt.php?ProjRev=$this_file'><span class='bodyTextLG'>$this_file</span></a><br>";}}

Contents of the HTTPalt.php:

header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=$ProjRev");
header("Content-Length: ".filesize("../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?

3:03 pm on Aug 12, 2006 (gmt 0)


WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
votes: 0

I would try saving it using the top code first to be sure that portion is working correctly, if so, then it is most likely a header issue

take a look at this manual page, especially the comments, it might point you in the right direction