Link to home
Start Free TrialLog in
Avatar of Ryan_Kempt
Ryan_KemptFlag for Canada

asked on

HTTP FTP Download

Hello, I am attempting to simplify the process of downloading files from an FTP site for some users - I also only want to show and allow them to download a couple of the files.

So, basically I want them to login to a website (I can do this), and from there, list a couple of the files in the FTP (I can do this with PHP's php_nlist and some regular expressions). Now, what I don't understand is how to have them able to download the file from there...

I can print the filenames, I don't know how to have a download / Save As.. prompt pop up when they click one of the files, or anything - and once again I want them to see as little as possible - just click the file name, and a download prompt. Thanks.

Oh, and a basic version of the PHP section of my "download.html" looks something like this:
$conn = ftp_connect("") or die("Could not connect");

Open in new window

Avatar of hielo
Flag of Wallis and Futuna image

The user would need to specify the file(s) desired and for each selection you will need to do an ftp_get:

Once you have the file on your server,  your script should then open your copy of the file, read it's contents, and "pass it along" to the browser by echoing or printing its contents (You may have to specify the mime type for the file.)
You could do a
This way the user-browser is redirected to the ftp so you don't need to waste the bandwidth on your server. If the users can't use ftp-Protocol (e.g. firewall) you need ftp_get to copy the file loca to your server and then output the date you retrieved via ftP_get
Avatar of Ryan_Kempt


People are having FTP problems so I'm trying to have it send through HTTP basically without keeping a physical copy on the HTTP server. It is a complex and somewhat irritating (for me!) situation. I do appreciate the comments so far - keep 'em coming!
The problem with FTP_GET is that it saves it to the server it's being run on, rather than ask the user for a "Save as..." type prompt in their web browser.
>>The problem with FTP_GET is that it saves it to the server it's being run on, rather than ask the user for a "Save as..." type prompt in their web browser.
Yes, it save it to the local server, but after it is saved to the local server your script is supposed to fopen the copy of said file, send an appropriate header for the file. Ex: if the file is pdf, you would send:
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf

once you are done with the file, delete it from your local server
Thanks for the reply, I do have one concern though; the file is about 120 MB in size, I'm not even too worried about bandwidth, but I am concerned that it may take several minutes to even show a download prompt (since the file must be downloaded to the HTTP server first).
Well, if you don't want to cache the files on your local server, this is an issue that the client will have to deal with, since you are getting the file from a remote server and then relaying the file onto the client.
Avatar of hernst42
Flag of Germany image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I ended up using something else, but thanks for your help.