Prompted File Download Fails in IE

Posted on 2011-10-17
Last Modified: 2013-12-25

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], 

    // 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);

    // 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", 

    // 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", 

    // Content-type: TYPE
    printf("%s: %s\n", SYM_CONT_TYPE, fileType);

    // Content-length: LENGTH
    printf("%s: %u\n", SYM_CONT_LEN, size);


    // Print contents of file
    while(fgets(output, sizeof(output), file) != NULL)
        printf("%s", output);

    if(file != NULL)

    return 0;

Open in new window

Question by:sctccomm

    Accepted Solution

    Found out that Internet Explorer has quite a bit of problems supporting "Content-disposition".

    For "Content-Disposition: attachment, ...", all IE's seem to have trouble when you open this kind of page in a new window or tab.  Thus when creating a page, forcing a file download must be done within the same in window.

    Or I believe using <href> should always work.

    Author Comment


    Featured Post

    Training Course: Adobe Photoshop CC 2015

    Photoshop has become the standard in image manipulation among professional photographers and graphic designers. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Join & Write a Comment

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now