Results 1 to 6 of 6

Thread: Please Help Create Download Link.

  1. #1
    Join Date
    Jan 2006
    Posts
    227
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Please Help Create Download Link.

    Hi.

    I asked here before if it is possible to create a download link for a PDF file that opens if clicked the download without displaying the PDF file in the IE browser window and I've been told that it is not possible.
    Now I found this website and here it is possible.
    Please check out the PDF download link below the text content.

    Example Website

    As I understand it there is used javascript but I'm not sure.
    Can someone tell me how this is done?

    Thanks in advance.
    Cheng

  2. #2
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, basically the trick is server-side, because of "content-disposition" directive in server response. No javascript in there.

    If you have access to php or CGI scripts, you can add a wrapper that sends required header:

    In apache you can create .htaccess file with content like this:
    Code:
    Action downloader /cgi-bin/wrapme.php
    <Directory /path/to/files>
    AddHandler downloader .pdf
    </Directory>
    while the wrapme.php (in this case, a php written wrapper) is:
    PHP Code:
    <?php
    $file 
    $_SERVER['PATH_TRANSLATED'];
    if (
    file_exists($file)) {
      
    header('Content-type: application/pdf');
      
    header('Content-transfer-encoding: binary');
      
    header('Content-disposition: filename=' basename($file));
      
    header('Content-length: ' filesize($file));
      
    readfile("$file");
    } else {                                                                
      
    header("HTTP/1.0 404 Not found");                      
    }                                                                       
    ?>
    Last edited by ItsMeOnly; 10-28-2006 at 03:07 PM.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's not perfect, though. It all depends on the user's browser settings.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Actually, at least speaking from experience with NN4, Mozilla, Firefox, IEs, Opera and HotJava (tried them all, luck of having several computers-some with very old browsers)- this works, unless of course you mean when user selected "helper application" to open the filetype, and made it a default.

    You can always try pulling it as application/octet-stream too

  5. #5
    Join Date
    Jan 2006
    Posts
    227
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question

    Hi ItsMeOnly.
    Hi Twey.

    Thanks for all your replies.
    If I use this:
    In apache you can create .htaccess file with content like this:
    Code:
    Action downloader /cgi-bin/wrapme.php
    <Directory /path/to/files>
    AddHandler downloader .pdf
    </Directory>
    Is this mean that I have to place the PDF file in the cgi-bin folder?
    And where I want the link to appear I have to add the code and the path like in this example:
    Code:
    Action downloader /cgi-bin/wrapme.php
    <Directory /http://www.mysite.com/cgi-bin/file.pdf>
    AddHandler downloader .pdf
    </Directory>
    Did I enter the path correct or does it needs to be entered differently?
    Is there anything else I have to do to make it work?
    I want it to work for IE as regarding to the site stats 99% of the site visitors are IE users.

    Thanks again for your help.
    Cheng

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Is this mean that I have to place the PDF file in the cgi-bin folder?
    No, you'd have to place it in /path/to/files. Obviously you can modify this.
    Did I enter the path correct or does it needs to be entered differently?
    It should be a local path to a directory (hence <Directory>). Things starting with a protocol (http://, for example) are URLs, not paths, and should not begin with a slash (in fact, I don't think it is permissible to put URLs in this field, although I could be wrong).
    Action downloader /cgi-bin/wrapme.php
    Note that this should point to the wrapme.php file provided above.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •