Page 1 of 1
content-disposition header to remote file?
Posted: Tue Nov 25, 2008 2:21 am
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
Re: content-disposition header to remote file?
Posted: Tue Nov 25, 2008 5:42 am
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
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)
Re: content-disposition header to remote file?
Posted: Tue Nov 25, 2008 11:06 am
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
Re: content-disposition header to remote file?
Posted: Tue Nov 25, 2008 10:05 pm
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");

Re: content-disposition header to remote file?
Posted: Tue Nov 25, 2008 10:47 pm
by andrew_9
Excellent. Thanks again for your help.