Link, which always offers to save/open....

Discussion in 'HTML' started by jodleren, Mar 13, 2007.

  1. jodleren

    jodleren Guest

    Hi all

    I have seen this, and now I need it myself.

    I need a link to some files, which should not be opened by the browser
    or plugins. I want a window to pop up and the user should choose the
    action.
    Several email services have this. I have been looking into, but not
    figured it out.

    Any ideas?

    BR
    Sonnich
    jodleren, Mar 13, 2007
    #1
    1. Advertising

  2. jodleren wrote:

    > I need a link to some files, which should not be opened by the browser
    > or plugins.


    Google: HTTP Content-Disposition header

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

    * = I'm getting there!
    Toby A Inkster, Mar 13, 2007
    #2
    1. Advertising

  3. jodleren

    jodleren Guest

    On Mar 13, 5:18 pm, Toby A Inkster <>
    wrote:
    > jodleren wrote:
    > > I need a link to some files, which should not be opened by the browser
    > > or plugins.

    >
    > Google: HTTP Content-Disposition header


    You could be a little more specific...

    I found something and came up with:

    <?php
    $file=$_GET['file'];
    header('Content-type: application/force-download');
    header("Content-Disposition: attachment; filename=\"$file\"");
    readfile($file);
    ?>

    Though, this opens a window (when I use this from another link), is
    there a way to avoid the browser window?

    BR
    Sonnich

    Please CC to sonnich_at_hot_._ee
    jodleren, Mar 13, 2007
    #3
  4. jodleren wrote:
    > Toby A Inkster <> wrote:
    >
    >> Google: HTTP Content-Disposition header

    >
    > You could be a little more specific...
    > I found something


    Firstly, I was clearly sufficiently specific, in that it lead you to an
    answer.

    Secondly, I couldn't be very much more specific than I was, as you didn't
    mention any details of your hosting situation in your original post.
    (Operating system, server software, scripting languages, level of access,
    etc.)

    > and came up with:

    [...]
    > header('Content-type: application/force-download');


    Replace that line with a real content type. For example, if the file is a
    PDF, then the Content-Type should be "application/pdf". If it's a JPEG,
    then "image/jpeg". If you are really unable to determine the correct
    content type, use "application/octet-stream".

    Using made-up content types like the one you've used above may seem to be
    "convenient", but it harms the web as a whole.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

    * = I'm getting there!
    Toby A Inkster, Mar 13, 2007
    #4
  5. jodleren

    jodleren Guest

    > > and came up with:
    > [...]
    > > header('Content-type: application/force-download');

    >
    > Replace that line with a real content type. For example, if the file is a
    > PDF, then the Content-Type should be "application/pdf". If it's a JPEG,
    > then "image/jpeg". If you are really unable to determine the correct
    > content type, use "application/octet-stream".
    >
    > Using made-up content types like the one you've used above may seem to be
    > "convenient", but it harms the web as a whole.


    Since I can have _any_ file, where is there an overview of those or
    trick to get them?

    And since I open this from another window, is the a way to have a
    link, which goes directly to the open/save dialog. That is what I
    really need.

    BR
    Sonnich
    jodleren, Mar 14, 2007
    #5
  6. jodleren wrote:
    >>> and came up with:

    >> [...]
    >>> header('Content-type: application/force-download');

    >> Replace that line with a real content type. For example, if the file is a
    >> PDF, then the Content-Type should be "application/pdf". If it's a JPEG,
    >> then "image/jpeg". If you are really unable to determine the correct
    >> content type, use "application/octet-stream".
    >>
    >> Using made-up content types like the one you've used above may seem to be
    >> "convenient", but it harms the web as a whole.

    >
    > Since I can have _any_ file, where is there an overview of those or
    > trick to get them?
    >
    > And since I open this from another window, is the a way to have a
    > link, which goes directly to the open/save dialog. That is what I
    > really need.


    This question gets ask quite often, a a specific media is handled by the
    browser (open in the browser, open directly by the app or download) is
    browser setting so if the user has set it to open in the browser there
    is not much you can do about it.

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Mar 14, 2007
    #6
  7. jodleren

    jodleren Guest

    On Mar 13, 9:04 pm, Toby A Inkster <>
    wrote:
    > jodleren wrote:
    > > Toby A Inkster <> wrote:

    >
    > >> Google: HTTP Content-Disposition header

    >
    > > You could be a little more specific...
    > > I found something

    >
    > Firstly, I was clearly sufficiently specific, in that it lead you to an
    > answer.
    >
    > Secondly, I couldn't be very much more specific than I was, as you didn't
    > mention any details of your hosting situation in your original post.
    > (Operating system, server software, scripting languages, level of access,
    > etc.)
    >
    >
    >
    > > and came up with:

    > [...]
    > > header('Content-type: application/force-download');

    >
    > Replace that line with a real content type. For example, if the file is a
    > PDF, then the Content-Type should be "application/pdf". If it's a JPEG,
    > then "image/jpeg". If you are really unable to determine the correct
    > content type, use "application/octet-stream".


    Would there be a problem with getting the extension of the file and
    using it, such as:
    $ext = get_extension_of_file;

    header("Content-type: application/$ext");

    >
    > Using made-up content types like the one you've used above may seem to be
    > "convenient", but it harms the web as a whole.


    What do you think about this?
    header("Content-Disposition: attachment; filename=\"$file\"");

    Is there a place where headers are listed?
    I could use that now

    BR
    Sonnich
    jodleren, Mar 27, 2007
    #7
  8. jodleren

    jodleren Guest

    On Mar 14, 4:57 pm, "Jonathan N. Little" <>
    wrote:
    > jodleren wrote:


    > > And since I open this from another window, is the a way to have a
    > > link, which goes directly to the open/save dialog. That is what I
    > > really need.

    >
    > This question gets ask quite often, a a specific media is handled by the
    > browser (open in the browser, open directly by the app or download) is
    > browser setting so if the user has set it to open in the browser there
    > is not much you can do about it.


    Well... I am playing around with this again...

    my mail, www.hot.ee, has a way of doing it... but I have a feeling
    that they do it in some other way.
    Also, I recall lately, a window, which opens, then is closes/dialog
    opens, so only the dialog remains...
    There is a way out there...

    BR
    Sonnich
    jodleren, Mar 27, 2007
    #8
  9. jodleren

    John Hosking Guest

    jodleren wrote:
    > On Mar 13, 9:04 pm, Toby A Inkster <>
    > wrote:
    >
    >>jodleren wrote:
    >>
    >>>Toby A Inkster <> wrote:

    >>
    >>>>Google: HTTP Content-Disposition header

    >>


    > Would there be a problem with getting the extension of the file and
    > using it, such as:
    > $ext = get_extension_of_file;
    >
    > header("Content-type: application/$ext");


    The MIME type doesn't always (or even usually) match the file extension.

    >>Using made-up content types like the one you've used above may seem to be
    >>"convenient", but it harms the web as a whole.

    >
    > What do you think about this?
    > header("Content-Disposition: attachment; filename=\"$file\"");


    You'd also need to set the content-type to something nasty[1]. Please
    don't.

    > Is there a place where headers are listed?


    Google is your friend. Well, it's *our* friend, but you could use it too.

    Take a look at http://www.w3schools.com/media/media_mimeref.asp. I
    cannot vouch for the veracity of the content in that table, since
    www.w3schools.com isn't always accurate, but it will give you an idea of
    what you're dealing with. Note especially the links at the top of the
    page, leading you to the RFC (Request For Comment) documents which are
    the source of this information.

    [1]http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index3.html

    --
    john
    John Hosking, Mar 28, 2007
    #9
  10. On Mar 13, 10:56 am, "jodleren" <> wrote:
    > I have seen this, and now I need it myself.
    > I need a link to some files, which should not be opened by the browser
    > or plugins. I want a window to pop up and the user should choose the
    > action.


    This is my choice. You don' t have any say in what I do with the file.
    Travis Newbury, Mar 28, 2007
    #10
  11. jodleren

    Andy Dingley Guest

    On 13 Mar, 15:56, "jodleren" <> wrote:

    > I need a link to some files, which should not be opened by the browser
    > or plugins.


    Browsers only do this if two things happen: They know what type the
    document claims to be, and they know a way to handle this type.

    If they don't have both of these, then they are forced to ask the user
    what to open it with / save it as a file (or throw it away!).

    So if you serve a document (any document, even HTML) with the HTTP
    content-type of application/octet-stream, all the browser can do is
    handle it as raw bytes. It will almost certainly allow it to be saved,
    it might give an option to select a program to open it with.

    If you have a scripting language on the server, then you can do this
    easily. If you don't, but you're using Apache, then you can
    configure .htaccess to serve this content-type for all files with
    either a particular file extension, or files from a particular
    directory.
    Andy Dingley, Mar 28, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mathew George
    Replies:
    1
    Views:
    2,368
  2. F. GEIGER
    Replies:
    4
    Views:
    343
    Jarek Zgoda
    Oct 11, 2004
  3. BusyBoy
    Replies:
    2
    Views:
    601
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Oct 31, 2006
  4. jodleren
    Replies:
    0
    Views:
    354
    jodleren
    Mar 13, 2007
  5. Peter Hansen
    Replies:
    2
    Views:
    273
    Asm23
    Dec 27, 2007
Loading...

Share This Page