content-disposition header to remote file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andrew_9
Forum Newbie
Posts: 3
Joined: Tue Nov 25, 2008 2:10 am

content-disposition header to remote file?

Post by andrew_9 »

Is it possible to use the content-disposition header to point the user to a file that is at a location other than on the current server? For example, something like this:

Code: Select all

 
header('Content-Disposition: attachment; filename="http://www.php.net/images/php.gif"');
 
Let me know if you need more info or if my question is unclear. Thanks!

-Andrew
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: content-disposition header to remote file?

Post by novice4eva »

Yes first question would be: You didn't even bother to see what happens??
From what you want to achieve, its more like you want to go for

Code: Select all

header('location: '.$URL);
If you actually wanted someone to download some remote site(its content) then yeah go with your code but don't forget to echo the contents of the site while you are at it(hint: file_get_contents) and set the proper filename not whole URL(it doesn't return error but doesn't mean its proper either)
andrew_9
Forum Newbie
Posts: 3
Joined: Tue Nov 25, 2008 2:10 am

Re: content-disposition header to remote file?

Post by andrew_9 »

Thanks for the reply. I should have given more information with my first post. What I am trying to do is have the user automatically download an image from a remote server (nirvanix.com). For example, the user clicks on a download link, some verification is done, then they download an image (http://services.nirvanix.com/Prova/Prov ... hicago.jpg). Currently, I am using the method you described (header('location: '.$URL);). However, using this method the user is basically just redirected to the image. I would like to have the user prompted to save the file for download. This is slightly easier for the user, and this keeps the address of the image on the remote server relatively invisible from the user's perspective. I have used - header("Content-Disposition: attachment; filename='file.jpg'"); - in the past to refer to a local file, but I can't get it to work with a remote file. I tried the code I pasted above (and variations of that code), but I can't seem to figure it out. I tried playing around with file_get_contents() as you suggested, but that hasn't helped me. I am probably misunderstanding your suggestion.

So, is there a way to use the content-disposition header to point to a remote file (so the user downloads the file rather than is redirected to the page)? Is there an example of this that I could look at? Or, is there a better method to perform the desired function?

Thanks in advance for your help.

-Andrew
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: content-disposition header to remote file?

Post by novice4eva »

Code: Select all

 
header('Content-Disposition: attachment; filename="nice_place.gif"');
echo file_get_contents("http://node4.nirvanix.com/Prova/ProvaCloud/padentries/61850_Chicago.jpg");
 
:drunk:
andrew_9
Forum Newbie
Posts: 3
Joined: Tue Nov 25, 2008 2:10 am

Re: content-disposition header to remote file?

Post by andrew_9 »

Excellent. Thanks again for your help.
Post Reply