Starting a Download

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agisoec
    New Member
    • Oct 2006
    • 5

    Starting a Download

    Hi, All,

    I'm a bit new to this forum, and not too sharp at designing pages, so please bear with me. I posted a question in another forum and it was suggested that it might be better here.

    I have built a web page (HTML) and a PDF document. I can upload these and anything else I need to my ISP server. I know that if there is a HTML link to the PDF document, and someone viewing the page clicks on the link, the PDF will open on their computer and they can right-click and save-as. That's not what I'm trying to accomplish, but may be my only way.

    What I want to happen is to have a "download" link in the web page so that when it is clicked it causes a download pop-up to occur that has the run-save-cancel options. I've seen this many times when d/l'ing software, etc., and I imagine you have also. I think the pop-up is titled "Download Manager".

    I've searched and searched on the web for download managers, but they all seem to control d/l's inbound to my computer, not the ones outbound.

    Any help would be greatly appreciated. If something's not clear, tell me what and I'll to explain better.

    Thanks much. Earl
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    This may be what you are looking for. It downloads PDFs and other types. You'll have to install it at your server. The last lines show an example of how to call it from a HTML script.
    [php]
    <?php
    // place this code inside a php file and call it f.e. "download.p hp"
    // play with the path if the document root does noet exist
    $path = $_SERVER['DOCUMENT_ROOT']."/tst/downloads/";
    $fullPath = $path.$_GET['download_file'];

    if ($fd = fopen ($fullPath, "r")) {
    $fsize = filesize($fullP ath);
    $path_parts = pathinfo($fullP ath);
    $ext = strtolower($pat h_parts["extension"]);
    switch ($ext) {
    case "pdf":
    header("Content-type: application/pdf"); // add here more headers for diff. extensions
    header("Content-Disposition: attachment; filename=\"".$p ath_parts["basename"]."\""); // use 'attachement' to force a download
    break;
    default;
    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=\"".$p ath_parts["basename"]."\"");
    }
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while(!feof($fd )) {
    $buffer = fread($fd, 2048);
    echo $buffer;
    }
    }
    fclose ($fd);
    exit;
    // example: place this kind of link into your document where the download is shown:
    // <a href="download. php?download_fi le=MyDocument.p df">Download here</a>
    ?>
    [/php]

    Ronald :cool:

    Comment

    • agisoec
      New Member
      • Oct 2006
      • 5

      #3
      Hey, Ronald:
      Thanks for the reply. I tried with not much luck. I contacted my ISP and they don't support PHP, so I guess I'm stuck with the old right-click and save-as. I put the code you offered up as a PHP file, but when I linked to it from HTML it said the file type was unknown and wanted to download. That's close, but not what I was hoping to accomplish. Oh, well....good try.
      EARL

      Comment

      Working...