download-header not working in IE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Thorstens

    download-header not working in IE

    Hi,

    i try to give my script headers so the output text would be downloaded in
    the client's browser and not displayed. But it doesn't work at all in my IE
    6 and Opera.

    <?
    header("Content-Type: application/octet-stream");
    header("Content-Length: 5");
    header("Content-Transfer-Encoding: binary");
    header("Content-Disposition: attachment; filename=\"game data.txt\"");

    echo "hello";
    ?>

    I have an Apache 1 installed on my system, can it be that it is
    misconfigured and sends the headers in a wrong way? How can i change this?

    Help please,

    bye,
    Frank


  • Eric Ellsworth

    #2
    Re: download-header not working in IE

    What error message do you get?

    Also, recall that once the script sends any text, it cannot subsequently
    send headers (PHP should complain about this if error reporting is not
    turned off).

    EE

    ----- Original Message -----
    From: "Frank Thorstens" <FrankThorstens @gmx.de>
    Newsgroups: comp.lang.php
    Sent: Wednesday, November 05, 2003 6:15 PM
    Subject: download-header not working in IE

    [color=blue]
    > Hi,
    >
    > i try to give my script headers so the output text would be downloaded in
    > the client's browser and not displayed. But it doesn't work at all in my[/color]
    IE[color=blue]
    > 6 and Opera.
    >
    > <?
    > header("Content-Type: application/octet-stream");
    > header("Content-Length: 5");
    > header("Content-Transfer-Encoding: binary");
    > header("Content-Disposition: attachment; filename=\"game data.txt\"");
    >
    > echo "hello";
    > ?>
    >
    > I have an Apache 1 installed on my system, can it be that it is
    > misconfigured and sends the headers in a wrong way? How can i change[/color]
    this?[color=blue]
    >
    > Help please,
    >
    > bye,
    > Frank
    >
    >[/color]

    "Frank Thorstens" <FrankThorstens @gmx.de> wrote in message
    news:boc0b9$1cq mf7$1@ID-202045.news.uni-berlin.de...[color=blue]
    > Hi,
    >
    > i try to give my script headers so the output text would be downloaded in
    > the client's browser and not displayed. But it doesn't work at all in my[/color]
    IE[color=blue]
    > 6 and Opera.
    >
    > <?
    > header("Content-Type: application/octet-stream");
    > header("Content-Length: 5");
    > header("Content-Transfer-Encoding: binary");
    > header("Content-Disposition: attachment; filename=\"game data.txt\"");
    >
    > echo "hello";
    > ?>
    >
    > I have an Apache 1 installed on my system, can it be that it is
    > misconfigured and sends the headers in a wrong way? How can i change[/color]
    this?[color=blue]
    >
    > Help please,
    >
    > bye,
    > Frank
    >
    >[/color]


    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: download-header not working in IE

      "Frank Thorstens" <FrankThorstens @gmx.de> wrote in message news:<boc0b9$1c qmf7$1@ID-202045.news.uni-berlin.de>...[color=blue]
      > Hi,
      >
      > i try to give my script headers so the output text would be downloaded in
      > the client's browser and not displayed. But it doesn't work at all in my IE
      > 6 and Opera.
      >
      > <?
      > header("Content-Type: application/octet-stream");
      > header("Content-Length: 5");
      > header("Content-Transfer-Encoding: binary");
      > header("Content-Disposition: attachment; filename=\"game data.txt\"");
      >
      > echo "hello";
      > ?>
      >
      > I have an Apache 1 installed on my system, can it be that it is
      > misconfigured and sends the headers in a wrong way? How can i change this?
      >
      > Help please,[/color]

      IE needs special headers. Read the notes at


      <?php

      header('Content-Type: XXXXXXXXXXXXXX' );
      //IE need specific header
      if (strstr($_SERVE R['HTTP_USER_AGEN T'], "MSIE"))
      {
      header('Content-Disposition: inline; filename="'.$fi le_name.'"');
      header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
      header('Pragma: public');
      }
      else
      {
      header('Content-Disposition: attachment;
      filename="'.$fi le_name.'"');
      header('Pragma: no-cache');
      }


      ?>


      ---
      "The world is too dangerous to live in—not because of the people who
      do evil, but because of the people who sit and let it happen"---Albert
      Einstein
      Email: rrjanbiah-at-Y!com

      Comment

      • Frank Thorstens

        #4
        Re: download-header not working in IE

        Hi,
        [color=blue][color=green]
        > > i try to give my script headers so the output text would be downloaded[/color][/color]
        in[color=blue][color=green]
        > > the client's browser and not displayed. But it doesn't work at all in[/color][/color]
        my[color=blue]
        > IE[color=green]
        > > 6 and Opera.[/color]
        > What error message do you get?
        >
        > Also, recall that once the script sends any text, it cannot subsequently
        > send headers (PHP should complain about this if error reporting is not
        > turned off).[/color]

        I get no error, but it just shows the text in the browser.
        I send the headers before any other output.

        bye,
        Frank


        Comment

        • Frank Thorstens

          #5
          Re: download-header not working in IE

          Hi,
          [color=blue][color=green]
          > > i try to give my script headers so the output text would be downloaded[/color][/color]
          in[color=blue][color=green]
          > > the client's browser and not displayed. But it doesn't work at all in[/color][/color]
          my IE[color=blue][color=green]
          > > 6 and Opera.[/color]
          > IE needs special headers. Read the notes at
          > http://in.php.net/header[/color]

          Thanks, i tried your code but still no luck, the IE just shows the text in
          the browser. :-(

          bye,
          Frank


          Comment

          • Tom Thackrey

            #6
            Re: download-header not working in IE


            On 5-Nov-2003, "Frank Thorstens" <FrankThorstens @gmx.de> wrote:
            [color=blue][color=green][color=darkred]
            > > > i try to give my script headers so the output text would be downloaded[/color][/color]
            > in[color=green][color=darkred]
            > > > the client's browser and not displayed. But it doesn't work at all in[/color][/color]
            > my IE[color=green][color=darkred]
            > > > 6 and Opera.[/color]
            > > IE needs special headers. Read the notes at
            > > http://in.php.net/header[/color]
            >
            > Thanks, i tried your code but still no luck, the IE just shows the text in
            > the browser. :-([/color]

            Here's what works for me:
            I can't remember where I got it, maybe here. :-)

            $filename = $ex_name.'.csv' ;
            $mime_type = 'text/x-csv';
            header('Content-Type: ' . $mime_type);
            header('Expires : ' . gmdate('D, d M Y H:i:s') . ' GMT');
            if (strpos($_SERVE R["HTTP_USER_AGEN T"],'MSIE')!==fals e)
            {
            header('Content-Disposition: inline; filename="' . $filename . '"');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            } else
            {
            header('Content-Disposition: attachment; filename="' . $filename . '"');
            header('Pragma: no-cache');
            }

            --
            Tom Thackrey

            tom (at) creative (dash) light (dot) com
            do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

            Comment

            • John Dunlop

              #7
              Re: download-header not working in IE

              Frank Thorstens wrote:
              [color=blue]
              > i try to give my script headers so the output text would be downloaded in
              > the client's browser and not displayed.[/color]

              Why?

              --
              Jock

              Comment

              • Frank Thorstens

                #8
                Re: download-header not working in IE

                > > i try to give my script headers so the output text would be downloaded
                in[color=blue][color=green]
                > > the client's browser and not displayed.[/color]
                >
                > Why?[/color]

                The client have to open this file in excel. So it's more convinient if he
                directly saves the data instead of seeing it in the browser, than have to
                save it as text etc.

                bye,
                Frank


                Comment

                • John Dunlop

                  #9
                  Re: download-header not working in IE

                  Frank Thorstens wrote:
                  [color=blue]
                  > The client have to open this file in excel. So it's more convinient if he
                  > directly saves the data instead of seeing it in the browser, than have to
                  > save it as text etc.[/color]

                  Why is the client limited to those options?

                  --
                  Jock

                  Comment

                  • Frank Thorstens

                    #10
                    Re: download-header not working in IE

                    > > The client have to open this file in excel. So it's more convinient if
                    he[color=blue][color=green]
                    > > directly saves the data instead of seeing it in the browser, than have[/color][/color]
                    to[color=blue][color=green]
                    > > save it as text etc.[/color]
                    >
                    > Why is the client limited to those options?[/color]

                    not sure, if I understand your question. The user on the client side wants
                    to put the downloaded Data into an excel sheet. So it's more convinient if
                    he directly saves the file and open it in excel.

                    bye,
                    Frank


                    Comment

                    • John Dunlop

                      #11
                      Re: download-header not working in IE

                      Frank Thorstens wrote:
                      [color=blue]
                      > The user on the client side wants to put the downloaded Data into an excel
                      > sheet.[/color]

                      What format is the data in?
                      [color=blue]
                      > So it's more convinient if he directly saves the file and open it in excel.[/color]

                      If it's an Excel spreadsheet, the registered MIME media type is
                      application/vnd.ms-excel.

                      --
                      Jock

                      Comment

                      • Frank Thorstens

                        #12
                        Re: download-header not working in IE

                        > > The user on the client side wants to put the downloaded Data into an
                        excel[color=blue][color=green]
                        > > sheet.[/color]
                        > What format is the data in?[/color]

                        it's a comma-separated text file.
                        The MIME for comma-separeted text files also didn't work. I found out, what
                        was wrong, see the other post.

                        but thanks for replying,
                        Frank


                        Comment

                        • Frank Thorstens

                          #13
                          Re: download-header not working in IE

                          ok, i tested always by putting the URL of the PHP page into the address
                          field of the browser.
                          I now found, that the download is initiated by a href to the page or by
                          other way of linking.

                          So it seems to work.

                          Thank all you guys for replying.

                          bye,
                          Frank


                          Comment

                          • John Dunlop

                            #14
                            Re: download-header not working in IE

                            Frank Thorstens wrote:
                            [color=blue]
                            > it's a comma-separated text file.
                            > The MIME for comma-separeted text files also didn't work.[/color]

                            There is no registered MIME media type for that format. You
                            might've used text/x-csv or suchlike. Whatever you use, the major
                            type should be text.

                            --
                            Jock

                            Comment

                            • R. Rajesh Jeba Anbiah

                              #15
                              Re: download-header not working in IE

                              "Frank Thorstens" <FrankThorstens @gmx.de> wrote in message news:<bocu24$1c bjpc$1@ID-202045.news.uni-berlin.de>...[color=blue]
                              > Hi,
                              >[color=green][color=darkred]
                              > > > i try to give my script headers so the output text would be downloaded[/color][/color]
                              > in[color=green][color=darkred]
                              > > > the client's browser and not displayed. But it doesn't work at all in[/color][/color]
                              > my IE[color=green][color=darkred]
                              > > > 6 and Opera.[/color]
                              > > IE needs special headers. Read the notes at
                              > > http://in.php.net/header[/color]
                              >
                              > Thanks, i tried your code but still no luck, the IE just shows the text in
                              > the browser. :-([/color]

                              In my experience, it won't download if you call it directly.
                              But, it will work if you call from another script by clicking or by
                              POST or GET.

                              ---
                              "The world is too dangerous to live in—not because of the people who
                              do evil, but because of the people who sit and let it happen"---Albert
                              Einstein
                              Email: rrjanbiah-at-Y!com

                              Comment

                              Working...