Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

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

0
10 Posted

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

0
10

(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://example.com/scriptname?name1=value1&name2=value2 Instead, try calling it as http://example.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://example.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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.