header() for download - pb in ns7

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

    header() for download - pb in ns7

    Hi, I have made a php page where people can configure a javascript online
    with a preview and then dowload the result. Here is the code:
    <?
    // Some code that create a temp file ($file handler = $fd) and write the
    script

    // Send the file
    header("content-type: text/plain");
    header("Content-length: ".filesize($fil e));
    header('Content-Disposition: attachment; filename="scrip t_name.js"');
    flush();
    while(!feof($fd )){
    echo fread($fd, 1024);
    flush();
    }
    fclose($fd);
    ?>

    Everything works fine with IE, Mozilla, FireFox and Opera. But with Netscape
    (7.0) no file is sent and I end up with a blank page. But still with
    Netscape, if I right-click the link and choose save as..., then it works ok
    Any idea ?

    Thanks
    Dae


  • Daedalus

    #2
    Re: header() for download - pb in ns7

    Looks like Netscape (at least 7.0) don't want to download text/plain even
    with attachment specified.

    [color=blue]
    > Hi, I have made a php page where people can configure a javascript online
    > with a preview and then dowload the result. Here is the code:
    > <?
    > // Some code that create a temp file ($file handler = $fd) and write the
    > script
    >
    > // Send the file
    > header("content-type: text/plain");
    > header("Content-length: ".filesize($fil e));
    > header('Content-Disposition: attachment; filename="scrip t_name.js"');
    > flush();
    > while(!feof($fd )){
    > echo fread($fd, 1024);
    > flush();
    > }
    > fclose($fd);
    > ?>
    >
    > Everything works fine with IE, Mozilla, FireFox and Opera. But with[/color]
    Netscape[color=blue]
    > (7.0) no file is sent and I end up with a blank page. But still with
    > Netscape, if I right-click the link and choose save as..., then it works[/color]
    ok[color=blue]
    > Any idea ?
    >
    > Thanks
    > Dae[/color]


    Comment

    • Hilarion

      #3
      Re: header() for download - pb in ns7

      Have you tried specifying different MIME type? Eg. "text/javascript" ?

      Hilarion


      Comment

      • Daedalus

        #4
        Re: header() for download - pb in ns7


        "Hilarion" <hilarion@SPAM. op.SMIECI.pl> wrote in message
        news:cnvc3n$d9e $1@news.onet.pl ...[color=blue]
        > Have you tried specifying different MIME type? Eg. "text/javascript" ?[/color]

        Yes I tried. But actually I already solved my problem, I just forgot to post
        my solution here;
        So "text/plain", "text/javascript" and "applicatio n/x-javascript" behave the
        same way: printing the content of the file in the browser (Netscape 7).
        I finally used "applicatio n/octet-stream" to force NS to download it. Only
        problem is that without some setting changes NS always try to save the file
        as script_name.js. php. Anyway most people will just remove the php extension
        and even if they don't the script will work with the php extension.

        Dae


        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: header() for download - pb in ns7

          "Daedalus" <arsenault.dani el@videotron.ca > wrote in message news:<30grsoF2v aomvU1@uni-berlin.de>...[color=blue]
          > "Hilarion" <hilarion@SPAM. op.SMIECI.pl> wrote in message
          > news:cnvc3n$d9e $1@news.onet.pl ...[color=green]
          > > Have you tried specifying different MIME type? Eg. "text/javascript" ?[/color]
          >
          > Yes I tried. But actually I already solved my problem, I just forgot to post
          > my solution here;
          > So "text/plain", "text/javascript" and "applicatio n/x-javascript" behave the
          > same way: printing the content of the file in the browser (Netscape 7).
          > I finally used "applicatio n/octet-stream" to force NS to download it. Only
          > problem is that without some setting changes NS always try to save the file
          > as script_name.js. php. Anyway most people will just remove the php extension
          > and even if they don't the script will work with the php extension.[/color]

          You may want to look at the usernotes section of
          <http://in2.php.net/header> Each browser requires different headers.

          --
          <?php echo 'Just another PHP saint'; ?>
          Email: rrjanbiah-at-Y!com

          Comment

          • Daedalus

            #6
            Re: header() for download - pb in ns7

            > You may want to look at the usernotes section of[color=blue]
            > <http://in2.php.net/header> Each browser requires different headers.
            >
            > --
            > <?php echo 'Just another PHP saint'; ?>
            > Email: rrjanbiah-at-Y!com[/color]

            Yes I've already look there (including the user notes). And AFAIK browsers
            do not really require different headers, but they may behave differently
            with some headers (mostly the non HTTP1.1 standard headers like
            Content-Disposition). This is "AFAIK". Anyone, feel free to correct me.

            Dae


            Comment

            • J.O. Aho

              #7
              Re: header() for download - pb in ns7

              Daedalus wrote:[color=blue]
              > Hi, I have made a php page where people can configure a javascript online
              > with a preview and then dowload the result.
              > Everything works fine with IE, Mozilla, FireFox and Opera. But with Netscape
              > (7.0) no file is sent and I end up with a blank page. But still with
              > Netscape, if I right-click the link and choose save as..., then it works ok[/color]

              I guess it has to do whit some content-type detections in netscape (based on
              mozilla 1.0.1 if I remeber it right), I would make a browser type check and if
              it detects netscape 7.0, then use another content-type, this is how things
              like this are usually solved in MSIE when it don't want to work.


              //Aho

              Comment

              • R. Rajesh Jeba Anbiah

                #8
                Re: header() for download - pb in ns7

                "Daedalus" <arsenault.dani el@videotron.ca > wrote in message news:<30hkjhF2u nq30U1@uni-berlin.de>...[color=blue][color=green]
                > > You may want to look at the usernotes section of
                > > <http://in2.php.net/header> Each browser requires different headers.[/color]
                >
                > Yes I've already look there (including the user notes). And AFAIK browsers
                > do not really require different headers, but they may behave differently
                > with some headers (mostly the non HTTP1.1 standard headers like
                > Content-Disposition). This is "AFAIK". Anyone, feel free to correct me.[/color]

                Sorry, didn't mean all the headers; but to force download...
                <http://in.php.net/header#21708> and
                <http://cvs.sourceforge .net/viewcvs.py/phpmyadmin/phpMyAdmin/export.php?rev= 2.17&view=marku p>
                (search for "// Download").

                --
                <?php echo 'Just another PHP saint'; ?>
                Email: rrjanbiah-at-Y!com

                Comment

                Working...