sctccomm
asked on
Prompted File Download Fails in IE
Hello,
I have 2 problems:
1. File download fails in all IE's.
I have written a CGI page that will allow a user to download the
contents of a file. But when the page loads, prompts the user to
save, an error message will appear.
This code works fine in all Firefox's, but I have searched through
many forums and have yet to get a solution for this problem.
2. File name of download is incorrect.
Ideally I pass in information to the CGI file with the information
about the file to download using the Query string. When I do this
the download dialog box shows part of the Query string as the
file name instead of that specified in the Content-disposition.
And even though if I hard code file information into the CGI, thus
leaving the Query string blank, the name of the CGI file is used
instead of the Content-disposition filename.
I have attached a screenshot of the error and a copy of the
CGI code.
I have 2 problems:
1. File download fails in all IE's.
I have written a CGI page that will allow a user to download the
contents of a file. But when the page loads, prompts the user to
save, an error message will appear.
This code works fine in all Firefox's, but I have searched through
many forums and have yet to get a solution for this problem.
2. File name of download is incorrect.
Ideally I pass in information to the CGI file with the information
about the file to download using the Query string. When I do this
the download dialog box shows part of the Query string as the
file name instead of that specified in the Content-disposition.
And even though if I hard code file information into the CGI, thus
leaving the Query string blank, the name of the CGI file is used
instead of the Content-disposition filename.
I have attached a screenshot of the error and a copy of the
CGI code.
#define SYM_CACHE_CTRL "Cache-Control"
#define SYM_NO_CACHE "no-cache"
#define SYM_REVALIDATE "must-revalidate"
#define SYM_POST_CHK "post-check"
#define SYM_PRE_CHK "pre-check"
#define SYM_PRAG_PUBLIC "Pragma: Public"
#define SYM_PRAG_PRIVATE "Pragma: Private"
#define SYM_CONT_TYPE "Content-Type"
#define SYM_CONT_LEN "Content-Length"
#define SYM_CONT_DISP "Content-Disposition"
#define SYM_ATTACH "attachment"
#define SYM_FILENAME "filename"
#define SYM_XCONT_TYPE "X-Content-Type-Options"
#define SYM_NO_SNIFF "nosniff"
#define MIME_HEADER "MIME-Version 1.0"
#define TYPE_TXT_PLAIN "text/plain"
#define MAX_FILE_SIZE 50
#define MAX_PATH_SIZE (200 + MAX_FILE_SIZE)
#define MAX_TEXT_SIZE 100
SINT32 main(SINT32 argc, SINT8 *argv[])
{
UINT32 size;
FILE *file = NULL;
SINT8 fileName[MAX_FILE_SIZE],
fileSrc[MAX_PATH_SIZE],
fileType[MAX_TEXT_SIZE],
output[MAX_TEXT_SIZE];
// File type, name, source
/* if(wbm_lib_param_get(WBM_PARAM_TYPE, fileType) == FAIL ||
wbm_lib_param_get(WBM_PARAM_NAME, fileName) == FAIL ||
wbm_lib_param_get(WBM_PARAM_SRC, fileSrc) == FAIL)
{
return FAIL;
}
*/
sprintf(fileSrc, "%s", "/var/config/config.conf");
sprintf(fileType, "%s", "text/plain");
sprintf(fileName, "%s", "Config.conf");
// Open file
if((file = fopen(fileSrc, "r")) == NULL)
{
return FAIL;
}
fseek(file, 0, SEEK_END);
size = ftell(file);
rewind(file);
// MIME-Version 1.0
// printf("%s\n", MIME_HEADER);
// Cache-Control: must-revalidate, post-check=0, pre-check=0
// printf("%s: %s\n", SYM_CACHE_CTRL, SYM_NO_CACHE);
// printf("%s: %s, %s=0, %s=0\n",
// SYM_CACHE_CTRL, SYM_REVALIDATE, SYM_POST_CHK, SYM_PRE_CHK);
// Pragma: Public
// printf("%s\n", SYM_PRAG_PUBLIC);
// X-Content-Type-Options: nosniff
// printf("%s: %s\n", SYM_XCONT_TYPE, SYM_NO_SNIFF);
// Content-disposition: attachment; filename=NAME;
printf("%s: %s; %s=\"%s\";\n",
SYM_CONT_DISP, SYM_ATTACH, SYM_FILENAME, fileName);
// Content-type: TYPE
printf("%s: %s\n", SYM_CONT_TYPE, fileType);
// Content-length: LENGTH
printf("%s: %u\n", SYM_CONT_LEN, size);
printf("\n");
// Print contents of file
while(fgets(output, sizeof(output), file) != NULL)
{
printf("%s", output);
}
if(file != NULL)
{
fclose(file);
}
return 0;
}
Download-Error.PNG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
http://www.velocityreviews.com/forums/t388919-the-filename-set-in-the-response-setheader-content-disposition-attachment-filename-test-csv-is-being-ignored.html