[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
    Search the FAQ Archives

Single Page

Top Document: FAQ: Frequently Asked Questions about CGI Programming
Previous Document: 3.21 How can I prevent my CGI results being cached by the browser?
Next Document: SECTION 4 - TROUBLESHOOTING A CGI APPLICATION


3.22 How can I control the default filename when downloading a file via CGI?



	(from a newsgroup post by Matthew Healy)

One option, assuming you aren't already using the PATH_INFO
environment variable, is just to call your CGI script with extra
path information.

For example, suppose the URL to your script is actually

http://server.com/scriptname?name1=value1&name2=value2

Instead, try calling it as

http://server.com/scriptname/filename.ext?name1=value1&name2=value2

and note that you need to escape the URL if it's in an HTML page:

http://server.com/scriptname/filename.ext?name1=value1&name2=value2

And probably the browser will assign the name given in the last chunk
as the suggested filename for downloading.

This works because the http server looks for the program file to run,
then passes any extra path to the program as PATH_INFO variable; the
browser cannot tell where the SCRIPT_NAME part ends and the PATH_INFO
part begins.

This can also be very useful if you want one script to generate more
than one filename -- the script can check the PATH_INFO value and
alter its response accordingly...




Top Document: FAQ: Frequently Asked Questions about CGI Programming
Previous Document: 3.21 How can I prevent my CGI results being cached by the browser?
Next Document: SECTION 4 - TROUBLESHOOTING A CGI APPLICATION

Single Page


[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
Nick Kew <nick@webthing.com>

Last Update December 05 2008 @ 00:13 AM

© 2008 FAQS.ORG. All rights reserved.