views:

97

answers:

2

I was wondering if there was any way in PHP to pass an external download off to a user? What I would like to do with the script is depending on certain conditions, send the user a file from server A or server B. However, I don't want the user to know the direct url to either server.

Ex: User visits (which is on server C): http://example.com/download?id=1234 Server A's Address to file: http://servera.com/1234.exe Server B's Address to file: http://serverb.com/1234.exe

Is there a way, that when someone visits http://example.com/download?id=1234, to send them the download of the other servers without giving the user the direct URL? I know I can do a file([external file here]). But I do not want all the bandwidth going through server C. Server C is pretty much just a redirect.

Thanks, James

+2  A: 

The client must know at some level which server they are downloading from, otherwise they wouldn't be able to connect to it.

EDIT:

If you don't want the address bar of the browser to change, you can try using the Content-disposition header like so:

header("Content-disposition: attachment;filename=1234.exe");
//then output the file contents

Note: this PHP script has to be on server A and server B. So server C will redirect to either http://servera.com/download.php or http://serverb.com/download.php.

Matt Bridges
Yes, I understand that, but can I do this through headers, so an average user will be able to see?
James Hartig
As a security feature, the browser will (or should) always tell the user from which server they are downloading a file.
Matt Bridges
That being said, if you pipe the file through PHP and give a `Content-disposition` header, the browser will likely not update the address bar.
Matt Bridges
Alright. Thanks for the update. I think I will have to go with that option. Thanks!
James Hartig
A: 

hum

You may be able by using NAT or a Proxy. But this will be very difficult.

Only by modifying the headers it probably won't work.

EDIT: No, I think, you would have to add a proxy for all your servers at once (e.g. gateway).

Emiswelt
Like I could do a proxy through apache with mod_proxy? That would still use the bandwidth on server C.
James Hartig