Prompt to "Save As" No Matter What The File Type

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

    Prompt to "Save As" No Matter What The File Type

    What I want is to have a link to a file (it could be a .zip, .exe, .jpg,
    ..txt or even .html) and when the user clicks on it they are prompted with
    the Save As box, as opposed to it opening in the browser.
    I think I need to do something like:

    $fp = fopen($filetoou tput, "rb");
    $thefile = fread($fp, filesize($thefi letooutput));
    header("Content-type: ???/???"); not sure what to put instead of the ???
    echo $thefile;

    If anyone can help that would be much appreciated
    Richie


  • Jedi121

    #2
    Re: Prompt to "Save As" No Matter What The File Type

    Richie a écrit le 27/01/2004 :[color=blue]
    > What I want is to have a link to a file (it could be a .zip, .exe, .jpg,
    > .txt or even .html) and when the user clicks on it they are prompted with
    > the Save As box, as opposed to it opening in the browser.
    > I think I need to do something like:
    >
    > $fp = fopen($filetoou tput, "rb");
    > $thefile = fread($fp, filesize($thefi letooutput));
    > header("Content-type: ???/???"); not sure what to put instead of the ???
    > echo $thefile;
    >
    > If anyone can help that would be much appreciated
    > Richie[/color]

    Don't mess up the Content-type header, consider using :
    <?php
    header("Content-disposition: attachment;
    filename=my_nam e_of_the_file") ;
    ?>
    But look at Google for know issues on some browser versions.


    Comment

    • Shawn Wilson

      #3
      Re: Prompt to &quot;Save As&quot; No Matter What The File Type

      Richie wrote:[color=blue]
      >
      > What I want is to have a link to a file (it could be a .zip, .exe, .jpg,
      > .txt or even .html) and when the user clicks on it they are prompted with
      > the Save As box, as opposed to it opening in the browser.
      > I think I need to do something like:
      >
      > $fp = fopen($filetoou tput, "rb");
      > $thefile = fread($fp, filesize($thefi letooutput));
      > header("Content-type: ???/???"); not sure what to put instead of the ???
      > echo $thefile;[/color]

      Google for content-disposition header. Set it to "attachment ", I think. That
      doesn't work on some browsers, though.

      Shawn
      --
      Shawn Wilson
      shawn@glassgian t.com

      Comment

      • Richie

        #4
        Re: Prompt to &quot;Save As&quot; No Matter What The File Type


        "Jedi121" <jedi121news@fr ee.fr.Removethi s> wrote in message
        news:mesnews.dd 047d41.6e4253bc .504.2689@free. fr.Removethis.. .[color=blue]
        > Richie a écrit le 27/01/2004 :[color=green]
        > > What I want is to have a link to a file (it could be a .zip, .exe, .jpg,
        > > .txt or even .html) and when the user clicks on it they are prompted[/color][/color]
        with[color=blue][color=green]
        > > the Save As box, as opposed to it opening in the browser.
        > > I think I need to do something like:
        > >
        > > $fp = fopen($filetoou tput, "rb");
        > > $thefile = fread($fp, filesize($thefi letooutput));
        > > header("Content-type: ???/???"); not sure what to put instead of the ???
        > > echo $thefile;
        > >
        > > If anyone can help that would be much appreciated
        > > Richie[/color]
        >
        > Don't mess up the Content-type header, consider using :
        > <?php
        > header("Content-disposition: attachment;
        > filename=my_nam e_of_the_file") ;
        > ?>
        > But look at Google for know issues on some browser versions.
        >
        >[/color]

        That worked great, thanks.
        Hopefully on the few browsers that it doesn't work on, it'll just open the
        file in the browser as normal

        Richie


        Comment

        • John Dunlop

          #5
          Re: Prompt to &quot;Save As&quot; No Matter What The File Type

          Richie wrote:
          [color=blue]
          > What I want[/color]

          Perhaps unwittingly, you've made known the root of the perceived
          problem already: what you want and what someone else wants aren't
          necessarily one and the same.
          [color=blue]
          > is to have a link to a file (it could be a .zip, .exe, .jpg, .txt or
          > even .html) and when the user clicks on it they are prompted with the
          > Save As box, as opposed to it opening in the browser.[/color]

          (a) What "Save As box"? My browser didn't come with one. ;-)

          (b) What makes you think that you know how I ought to deal with
          files?

          (c) Which piece of software would you have me open an HTML file with,
          if not my browser?
          [color=blue]
          > header("Content-type: ???/???"); not sure what to put instead of the ???[/color]

          The file's media type perchance? Here's the authoritative registry
          for Internet media types:

          ftp://ftp.isi.edu/in-notes/iana/assi...s/media-types/

          And you'll see that Content-Disposition -- a non-HTTP/1.1 header,
          defined in the experimental RFC1806 -- has been put forward as a
          suggestion in other followups, which have rightly warned against
          sending illegitimate Content-Type headers. If your wish is to convey
          presentational information, this is the logical way.

          But sending this header, with a disposition type of attachment, does
          *not* guarantee that a client will ask the user what she wants done
          with the file; not being part of the HTTP/1.1 draft standard,
          conforming applications aren't obliged to act upon Content-
          Disposition headers. I reckon RFC1806's intention is *not*, without
          a smidgen of a doubt, to provide servers with the mechanism to
          "force" particular actions on clients. Is that not your inference
          too?

          --
          Jock

          Comment

          • laidbak

            #6
            Re: Prompt to &quot;Save As&quot; No Matter What The File Type

            >doesn't work on some browsers, though.

            It should not work in IE 4.x browsers and below.
            _______________ _______________ ______
            Wil Moore III, MCP | Integrations Specialist | Senior Consultant
            DigitallySmooth Inc. | Quick Site Studio

            Comment

            Working...