开发者

Save output of CGI script under different filename than the script name

I have a Python CGI script script.py running on a server. It produces a CSV file as output. I want computer-inexperienced people that don't know about file extensions to be able to just save the file to their hard drive and use it by double-clicking.

The problem: If they now click "OK" in the save dialog of the browser, the saved file's name is script.py, instead of script.csv.

How can I set some sort of "de开发者_如何学Gofault filename" from within the CGI? Maybe some HTTP header trickery? I don't have access to the server configuration.


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

Yours would look like:

Content-Disposition: attachment; filename=script.csv

As well as setting the filename, this will tell the browser to save the file, rather than to open it inline.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜