Save CGI script output under a different file name than script name

I have a CGI Python script script.py running on a server. It creates a CSV file as output. I want computer inexperienced people who are not aware of file extensions to just save the file to their hard drive and use it with a double click.

Problem: if they now click "OK" in the browser save dialog, the name of the saved file is script.py instead of script.csv .

How can I set some kind of "default file name" from CGI? Maybe some kind of HTTP header trick? I do not have access to the server configuration.

+4
source share
1 answer

You need to set the Content-Disposition header with the filename attribute. See an earlier question for discussion.

Your will look like this:

 Content-Disposition: attachment; filename=script.csv 

As with setting the file name, this tells the browser to save the file, not open it.

+5
source

All Articles