Download link instead of open

Discussion in 'HTML' started by Tom Gao, Jan 3, 2005.

  1. Tom Gao

    Tom Gao Guest

    is there a way to force a download say if I point a url to a html file or a
    pdf file instead of opening it just force it to download it ?

    Thanks
    Tom
     
    Tom Gao, Jan 3, 2005
    #1
    1. Advertising

  2. Tom Gao

    WindAndWaves Guest

    "Tom Gao" <> wrote in message
    news:41d8c7db$0$5112$...
    > is there a way to force a download say if I point a url to a html file or

    a
    > pdf file instead of opening it just force it to download it ?
    >
    > Thanks
    > Tom
    >
    >


    Documents are always downloaded - except streaming objects - what do you
    want to achieve?
     
    WindAndWaves, Jan 3, 2005
    #2
    1. Advertising

  3. Tom Gao

    Tom Gao Guest

    I want to click on a link on the page and have a box popup which say do you
    want to save as...
    and save the HTML file instead of opening it in the browser

    Tom

    "WindAndWaves" <> wrote in message
    news:wQ3Cd.4612$...
    >
    > "Tom Gao" <> wrote in message
    > news:41d8c7db$0$5112$...
    > > is there a way to force a download say if I point a url to a html file

    or
    > a
    > > pdf file instead of opening it just force it to download it ?
    > >
    > > Thanks
    > > Tom
    > >
    > >

    >
    > Documents are always downloaded - except streaming objects - what do you
    > want to achieve?
    >
    >
     
    Tom Gao, Jan 3, 2005
    #3
  4. Tom Gao wrote:

    [top-posting corrected]

    > "WindAndWaves" <> wrote
    >
    >> "Tom Gao" <> wrote
    >>
    >>> is there a way to force a download say if I point a url to a
    >>> html file or apdf file instead of opening it just force it to
    >>> download it ?

    >>
    >> Documents are always downloaded - except streaming objects - what
    >> do you want to achieve?


    > I want to click on a link on the page and have a box popup which
    > say do you want to save as... and save the HTML file instead of
    > opening it in the browser


    Place a message on the page to advise your visitors to use:

    1. File > Save As... choice on their browser's menu.
    2. Right-click > Save As...

    You cannot force anything.

    --
    -bts
    -This space intentionally left blank.
     
    Beauregard T. Shagnasty, Jan 3, 2005
    #4
  5. Tom Gao

    Duende Guest

    While sitting in a puddle Beauregard T. Shagnasty scribbled in the mud:

    > You cannot force anything.


    Yes you can.
    I forced the lid off a jar of peanut butter today.

    --
    D?
    If it ain't broken fix it anyway.
     
    Duende, Jan 3, 2005
    #5
  6. Tom Gao

    Neal Guest

    On Mon, 3 Jan 2005 15:06:54 +1100, Tom Gao <>
    wrote:

    > is there a way to force a download say if I point a url to a html file
    > or a
    > pdf file instead of opening it just force it to download it ?



    Might be the first time this year this question has been asked! (Of
    course, we neglect the 200 times last year...)

    The answer is simply, no, no and, yes. No, I'm kidding. No.
     
    Neal, Jan 3, 2005
    #6
  7. Duende wrote:
    > While sitting in a puddle Beauregard T. Shagnasty scribbled in the mud:
    >>You cannot force anything.

    > Yes you can.
    > I forced the lid off a jar of peanut butter today.


    Did you? Or did the peanuts finally just give in?


    --
    -=tn=-
     
    Travis Newbury, Jan 3, 2005
    #7
  8. Tom Gao wrote:
    > is there a way to force a download say if I point a url to a html
    > file or a pdf file instead of opening it just force it to download it
    > ?
    >
    > Thanks
    > Tom


    You could zip the file up. The best thing to do is put a message near the
    download link advising the user to right click, and 'save as'.

    --
    Peter
    nativespace - Web Hosting and Domain Names
    Providers of Advanced, Affordable UK Web Hosting Since 2001
    http://www.nativespace.com - Mambo, Fantastico, Urchin, cPanel, MySQL
     
    Peter - nativespace hosting, Jan 3, 2005
    #8
  9. Neal wrote:
    > Might be the first time this year this question has been asked! (Of
    > course, we neglect the 200 times last year...)


    Don't you mean 365*27 times last year?
     
    Leif K-Brooks, Jan 3, 2005
    #9
  10. Duende wrote:

    > While sitting in a puddle Beauregard T. Shagnasty scribbled in the
    > mud:
    >
    >> You cannot force anything.

    >
    > Yes you can. I forced the lid off a jar of peanut butter today.


    Must have been a jar of Windows Peanut Butter. ;-)

    --
    -bts
    -This space intentionally left blank.
     
    Beauregard T. Shagnasty, Jan 3, 2005
    #10
  11. Tom Gao

    jhebbel

    Joined:
    Jul 18, 2012
    Messages:
    1
    WRONG WRONG WRONG!!!!

    I really hate it when people come on forums and ask legitimate question and halfwitted programming hacks shoot them down and tell them its impossible....

    There are 2 ways to do this, thats right not only is it NOT IMPOSSIBLE, there are 2 ways to do it!!!!

    Option 1, place your DL's inside a specific folder and create an .htaccess file to tell the browser to serve these as downloads instead of content.
    Code:
    <FilesMatch "\.(html|jpg|png|gif)$">
     header set Content-Disposition attachment
    </FilesMatch>
    Option 2, use a PHP script to serve the file with a modified header:
    PHP:
    <?php
    // Make sure only files in this directory are accessible by removing slashes
    $file str_replace('/','',$_GET['file']);
    $file str_replace('\\','',$file);
    // If the file doesn't exist, show an error message and leave
    if(!file_exists('downloads/' $file) {
      
    header("HTTP/1.0 404 Not Found");
      echo 
    'The selected file doesn\'t exist';
      exit;
    }
    // Tell the browser to download the file
    header('Content-type: application/octet-stream');
    header('Content-Disposition: attachment');
    // Output the file data
    echo file_get_contents('downloads/' $file);
    ?>
     
    jhebbel, Jul 18, 2012
    #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. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,625
    Steve C. Orr [MVP, MCSD]
    Mar 7, 2005
  2. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    846
    Kevin Spencer
    May 17, 2005
  3. Sebastian Schmidt

    execute html link instead of download

    Sebastian Schmidt, Dec 9, 2003, in forum: HTML
    Replies:
    10
    Views:
    5,926
    Sebastian Schmidt
    Dec 10, 2003
  4. Mufasa
    Replies:
    6
    Views:
    1,327
    Alexey Smirnov
    Oct 2, 2007
  5. John Murray

    Download instead of open file

    John Murray, Apr 27, 2006, in forum: Javascript
    Replies:
    5
    Views:
    130
    Randy Webb
    Apr 29, 2006
Loading...

Share This Page