Forum How do I...?

Naming generated file

someuser
I run prince through a perl cgi script and was wondering if it was possible to specify the name of the file rather than have it called what the script file name is. I can get it to do this when it opens a file download box (ie save as/open with), but not when it opens straight in the browser and then they click save a copy. I'm pretty sure there is no way but I always get bugged by my users about this so i'm just double checking.
mikeday
Sure, just print a Content-disposition header in the Perl script when you print out the Content-type header. Like this:
Content-disposition: attachment; filename=myfile.pdf

This will tell the browser to save the file rather than displaying it, and that the suggested filename is "myfile.pdf".

You can also specify "inline" instead of "attachment" to suggest that the browser should display the file on the page, eg. using the Acrobat plugin.
someuser
Yeah it works fine for content-disposition: attachment, but for content-disposition: inline it ignores the file name...
mikeday
Sorry, I misread your original question. You are quite right, it seems to be a common bug in browsers that the suggested filename is ignored when content-disposition is inline. The only possible workaround would be to change the original URL to include the suggested filename and have your CGI script ignore it, eg.
http://example.com/cgi-bin/mycgi.pl/myfile.pdf

This should prompt the browser to call the file "myfile.pdf".
someuser
Thanks, that did the trick and even worked with a querystring after it! Just like to say that your tech support is always fantastic! Thanks so much for the effort and prompt replies!