Forced download issue with IE6

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Rigby

    #1

    Forced download issue with IE6

    Hi folks,

    I appreciate that this topic of forced downloads has been discussed in
    various threads but my situtation is a little different to those that I
    have come across and am experiencing a wierd issue in IE6.

    Essentially I am executing a select query against a MySql database and
    taking the result of that query and building a csv stream on the fly to
    send to the browser as a forced download.

    I have a function which has been cobbled together from a few internet
    sources. Code below:

    function ForceDownload ($data, $name, $filesize=false ) {

    if ($filesize == false OR !is_numeric($fi lesize)) {
    $filesize = strlen($data);
    }

    $mimetype = 'application/force-download';

    header("Pragma: public");
    header("Expires : 0");
    header("Cache-Control: must-revalidate, post-check=0,
    pre-check=0");
    header("Cache-Control: private",false) ;
    header("Content-Transfer-Encoding: binary");
    header("Content-Type: " . $mimetype);
    header("Content-Length: " . $filesize);
    header("Content-Disposition: attachment; filename=\"" . $name .
    "\";" );

    echo $data;
    die();
    }

    I am calling it from my page like so:

    $result = GetContacts($se archTerm, $searchType);
    $data = '';
    while($row = mysql_fetch_ass oc($result)) {
    $data .= $row['ContactName'] . ',' . $row['Email'];
    }
    ForceDownload($ data, 'contactExport. csv');

    This works fine in Firefox but IE6 refuses to do anything at all. It
    doesn't even display the content of the stream inline (ie in the
    browser window).

    Any ideas greatly appreciated.

    Simon

  • Rik

    #2
    Re: Forced download issue with IE6

    Simon Rigby wrote:
    Hi folks,
    >
    I appreciate that this topic of forced downloads has been discussed in
    various threads but my situtation is a little different to those that
    I have come across and am experiencing a wierd issue in IE6.
    >
    Essentially I am executing a select query against a MySql database and
    taking the result of that query and building a csv stream on the fly
    to send to the browser as a forced download.
    >
    I have a function which has been cobbled together from a few internet
    sources. Code below:
    I don't know wether it's the problem but this:
    $mimetype = 'application/force-download';
    header("Content-Type: " . $mimetype);
    Is something that's very bad practise IMO.

    This is normally enough for me:
    header("Content-Disposition: attachment; filename=\"" . $name .
    "\";" );
    Grtz,
    --
    Rik Wasmus


    Comment

    • Simon Rigby

      #3
      Re: Forced download issue with IE6

      I'll try that Rik. But I'm interested to know why its bad practice?

      Simon

      Comment

      • Simon Rigby

        #4
        Re: Forced download issue with IE6

        Hmm. Actually thats still not working. Works in Firefox still but
        nothing in IE. Just a browser flash as the form posts and then nothing.
        Well not striclty true. The form posts back to itself and the
        underlying page is rendering correctly but no download.

        Simon Rigby wrote:
        I'll try that Rik. But I'm interested to know why its bad practice?
        >
        Simon

        Comment

        • John Dunlop

          #5
          Re: Forced download issue with IE6

          Simon Rigby:

          [re 'application/force-download' for CSVs]
          But I'm interested to know why its bad practice?
          because there's already a MIME type registered for CSV, text/csv.

          'application/force-download' isn't registered, and this subtype doesn't
          mark its proprietariness with 'x-' - going against the MIME spec.

          and content-type 'indicates the media type of the entity-body sent to
          the recipient' (RFC2616: 14.17); it doesn't disposition the message.

          more details in the archived discussions. HTH

          --
          Jock

          Comment

          • Simon Rigby

            #6
            Re: Forced download issue with IE6

            Ah right, yes I understand. I was under the impression that using
            anything that wouldnt be recognised by the browser was part of
            "forcing" the download. I get it!

            Does anyone know why this is nt working in IE6.

            I have cut down the code to just apply the content disposition header.
            Still workin Firefox but no joy in IE.

            Simon

            John Dunlop wrote:
            Simon Rigby:
            >
            [re 'application/force-download' for CSVs]
            >
            But I'm interested to know why its bad practice?
            >
            because there's already a MIME type registered for CSV, text/csv.
            >
            'application/force-download' isn't registered, and this subtype doesn't
            mark its proprietariness with 'x-' - going against the MIME spec.
            >
            and content-type 'indicates the media type of the entity-body sent to
            the recipient' (RFC2616: 14.17); it doesn't disposition the message.
            >
            more details in the archived discussions. HTH
            >
            --
            Jock

            Comment

            • Jerry Stuckle

              #7
              Re: Forced download issue with IE6

              Simon Rigby wrote:
              Ah right, yes I understand. I was under the impression that using
              anything that wouldnt be recognised by the browser was part of
              "forcing" the download. I get it!
              >
              Does anyone know why this is nt working in IE6.
              >
              I have cut down the code to just apply the content disposition header.
              Still workin Firefox but no joy in IE.
              >
              Simon
              >
              Probably because IE is ignoring the headers and doing what it wants -
              it's notorious for that.

              At this point, you'll probably get better responses in alt.html. This
              doesn't look like anything PHP is doing.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Simon Rigby

                #8
                Re: Forced download issue with IE6

                Thanks for the pointer Jerry.

                Simon

                Jerry Stuckle wrote:
                Simon Rigby wrote:
                Ah right, yes I understand. I was under the impression that using
                anything that wouldnt be recognised by the browser was part of
                "forcing" the download. I get it!

                Does anyone know why this is nt working in IE6.

                I have cut down the code to just apply the content disposition header.
                Still workin Firefox but no joy in IE.

                Simon
                >
                Probably because IE is ignoring the headers and doing what it wants -
                it's notorious for that.
                >
                At this point, you'll probably get better responses in alt.html. This
                doesn't look like anything PHP is doing.
                >
                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • s a n j a y

                  #9
                  Re: Forced download issue with IE6

                  Simon Rigby wrote:
                  Thanks for the pointer Jerry.
                  >
                  Simon
                  >
                  Jerry Stuckle wrote:
                  >Simon Rigby wrote:
                  >>Ah right, yes I understand. I was under the impression that using
                  >>anything that wouldnt be recognised by the browser was part of
                  >>"forcing" the download. I get it!
                  >>>
                  >>Does anyone know why this is nt working in IE6.
                  >>>
                  >>I have cut down the code to just apply the content disposition header.
                  >>Still workin Firefox but no joy in IE.
                  >>>
                  >>Simon
                  >>>
                  >Probably because IE is ignoring the headers and doing what it wants -
                  >it's notorious for that.
                  >>
                  >At this point, you'll probably get better responses in alt.html. This
                  >doesn't look like anything PHP is doing.
                  >>
                  >--
                  >============== ====
                  >Remove the "x" from my email address
                  >Jerry Stuckle
                  >JDS Computer Training Corp.
                  >jstucklex@attgl obal.net
                  >============== ====
                  >
                  This happened to me once while developing a J2EE application, but I
                  think it will apply here as well.

                  Try changing value for "expires". You can try making it something like
                  30 minutes to start with and then if that works, lower the value to few
                  seconds.

                  What IE does, in my opinion, is that it downloads the file first to disk
                  cache before it opens it. But as soon as download is finished, it
                  realizes that the content is supposed to be expire in 0 seconds, so it
                  doesn't display anything.

                  If I am correct, it used to give file not found error in older versions.
                  Try it and let me know. I am curious as well.

                  Comment

                  • Richard Levasseur

                    #10
                    Re: Forced download issue with IE6


                    Simon Rigby wrote:
                    Thanks for the pointer Jerry.
                    >
                    Simon
                    >
                    Jerry Stuckle wrote:
                    Simon Rigby wrote:
                    Ah right, yes I understand. I was under the impression that using
                    anything that wouldnt be recognised by the browser was part of
                    "forcing" the download. I get it!
                    >
                    Does anyone know why this is nt working in IE6.
                    >
                    I have cut down the code to just apply the content disposition header.
                    Still workin Firefox but no joy in IE.
                    >
                    Simon
                    >
                    Probably because IE is ignoring the headers and doing what it wants -
                    it's notorious for that.

                    At this point, you'll probably get better responses in alt.html. This
                    doesn't look like anything PHP is doing.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===
                    By and large, i find force-download and saying the content type is some
                    sort of other format (x-octet-stream, iirc) works fairly well in IE. I
                    always have had the sneaking suspicion IE caches any file it recognizes
                    regardless of what any header says, though.

                    If you resolve this _please_ post how you did it - this is a problem i
                    always run into with IE. The solution always seems to be different,
                    too.

                    Comment

                    • Simon Rigby

                      #11
                      Re: Forced download issue with IE6

                      I appreciate the help guys but I;m still not having a lot of luck. The
                      main difference I find in my example from others on the web is that the
                      examples I have seen apply to a file that already exsists, whereas in
                      my case I am setting the headers and then "echoing" the $data to the
                      browser. Could this be why its not working in IE? I;m really scratching
                      my nut on this one, especially as it works fine in Firefox.

                      Cheers

                      Simon

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: Forced download issue with IE6

                        Simon Rigby wrote:
                        I appreciate the help guys but I;m still not having a lot of luck. The
                        main difference I find in my example from others on the web is that the
                        examples I have seen apply to a file that already exsists, whereas in
                        my case I am setting the headers and then "echoing" the $data to the
                        browser. Could this be why its not working in IE? I;m really scratching
                        my nut on this one, especially as it works fine in Firefox.
                        >
                        Cheers
                        >
                        Simon
                        >
                        Simon,

                        Might I (again) suggest you ask in alt.html? This doesn't look like a
                        problem with PHP - if it were, it should act the same in both browsers.
                        Rather, it looks like something IE is doing differently.

                        And alt.html would have more experts on why IE works different than FF
                        with the same valid HTML.

                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        • Rik

                          #13
                          Re: Forced download issue with IE6

                          Jerry Stuckle wrote:
                          Simon Rigby wrote:
                          >I appreciate the help guys but I;m still not having a lot of luck.
                          >The main difference I find in my example from others on the web is
                          >that the examples I have seen apply to a file that already exsists,
                          >whereas in my case I am setting the headers and then "echoing" the
                          >$data to the browser. Could this be why its not working in IE? I;m
                          >really scratching my nut on this one, especially as it works fine in
                          >Firefox.
                          >>
                          >Cheers
                          >>
                          >Simon
                          >>
                          >
                          Simon,
                          >
                          Might I (again) suggest you ask in alt.html? This doesn't look like a
                          problem with PHP - if it were, it should act the same in both
                          browsers. Rather, it looks like something IE is doing differently.
                          >
                          And alt.html would have more experts on why IE works different than FF
                          with the same valid HTML.
                          Jerry, this has nothing to do with HTML :P.

                          Headers are part of the HTTP protocol, a markup language doesn't come into
                          play. You do have a point that in alt.html there are more people aware of
                          MSIE problems, so allthough it's offtopic there, they might give an answer.
                          alt.www.webmaster and the like seem more apropriate.

                          Grtz,
                          --
                          Rik Wasmus


                          Comment

                          • Jerry Stuckle

                            #14
                            Re: Forced download issue with IE6

                            Rik wrote:
                            Jerry Stuckle wrote:
                            >
                            >>Simon Rigby wrote:
                            >>
                            >>>I appreciate the help guys but I;m still not having a lot of luck.
                            >>>The main difference I find in my example from others on the web is
                            >>>that the examples I have seen apply to a file that already exsists,
                            >>>whereas in my case I am setting the headers and then "echoing" the
                            >>>$data to the browser. Could this be why its not working in IE? I;m
                            >>>really scratching my nut on this one, especially as it works fine in
                            >>>Firefox.
                            >>>
                            >>>Cheers
                            >>>
                            >>>Simon
                            >>>
                            >>
                            >>Simon,
                            >>
                            >>Might I (again) suggest you ask in alt.html? This doesn't look like a
                            >>problem with PHP - if it were, it should act the same in both
                            > browsers. Rather, it looks like something IE is doing differently.
                            >>
                            >>And alt.html would have more experts on why IE works different than FF
                            >>with the same valid HTML.
                            >
                            >
                            Jerry, this has nothing to do with HTML :P.
                            >
                            Headers are part of the HTTP protocol, a markup language doesn't come into
                            play. You do have a point that in alt.html there are more people aware of
                            MSIE problems, so allthough it's offtopic there, they might give an answer.
                            alt.www.webmaster and the like seem more apropriate.
                            >
                            Grtz,
                            Grtz,

                            Nope, alt.www.webmaster isn't an appropriate group, either. That's more
                            about webmastering - not the technical issues (although we do discuss
                            technical issues at times).

                            I recommended alt.html because that's the closest you get to http
                            protocol, and they discuss headers more than any other group I've been in.


                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • Simon Rigby

                              #15
                              Re: Forced download issue with IE6

                              Yes you may (again) suggest that I post in alt.html.

                              Thanks

                              Jerry Stuckle wrote:
                              Simon Rigby wrote:
                              I appreciate the help guys but I;m still not having a lot of luck. The
                              main difference I find in my example from others on the web is that the
                              examples I have seen apply to a file that already exsists, whereas in
                              my case I am setting the headers and then "echoing" the $data to the
                              browser. Could this be why its not working in IE? I;m really scratching
                              my nut on this one, especially as it works fine in Firefox.

                              Cheers

                              Simon
                              >
                              Simon,
                              >
                              Might I (again) suggest you ask in alt.html? This doesn't look like a
                              problem with PHP - if it were, it should act the same in both browsers.
                              Rather, it looks like something IE is doing differently.
                              >
                              And alt.html would have more experts on why IE works different than FF
                              with the same valid HTML.
                              >
                              --
                              =============== ===
                              Remove the "x" from my email address
                              Jerry Stuckle
                              JDS Computer Training Corp.
                              jstucklex@attgl obal.net
                              =============== ===

                              Comment

                              Working...