What HTTP header is needed to be returned so web browsers use the suggested filename? (File download from CGI in C)
We have a PDF file download link on a web page with a C language CGI program actually passing on the file from our embedded device's web server. The web server is custom coded because of severe memory limitations.
The suggested filename by the C program is "Manual.pdf".
On Internet Explorer 8, when we click on the link the usual "Open/Save" box opens with the suggested filename displayed being "download.pdf" which is wrong. On Firefox, the suggested filename is "download.cgi" which is worse. However both browsers correctly indicate that the download is a PDF type.
Here are a few unrelated snippets of code to show the headers we are returning:
{ CONTENT_TYPE_PDF, "application/pdf\nContent-Disposition:attachment;" }
sprintf(tmpBuf, "Content-Type: %s\n", get_tbl_string((tbl_str_itm_t*)content_type, session->response.contenttype));
strcpy(tmpBuf, "filename=Manual.pdf\n");
strcat(tmpBuf, "Cache-Control: no-cache, no-store\n");
Can anyone tell what we are doing wrong?
Any help greatly appreciated.
Best regards, Bert
The "filename" stuff is part of the content-disposition header.
Content-Disposition: attachment; filename=Manual.pdf
header is good solution, however it doesn't work well if your filename has non-english characters. Another solution is to append "/Manual.pdf" path to your cgi script, i.e. use URLs like: http://server/path/my.cgi/Manual.pdf
, and then your my.cgi
program will be called with PATH_INFO=/Manual.pdf
. For funky filenames, this works better than Content-Disposition header.
Update: If you are interested in browser support for Content-Disposition
header, check http://greenbytes.de/tech/tc2231/.
Update: Another interesting article on the topic: Link