Professional Web Applications Themes

starting a download within php - PHP Development

Hello, I want users to be able to download files on my website. The files will not be located on my site but on some other domain. I also want to be able to register the download first and then start it to the user. I imagine I would have a hyperlink on a page saying 'download here' This in turn would pass an id number to a page called download.php so the hyperlink would be "blah blah blah download.php?id=1234" etc. The download.php would also insert the date and time of the download into a my sql db. I can ...

  1. #1

    Default starting a download within php

    Hello,

    I want users to be able to download files on my website. The files will
    not be located on my site but on some other domain.

    I also want to be able to register the download first and then start it
    to the user.

    I imagine I would have a hyperlink on a page saying 'download here'
    This in turn would pass an id number to a page called download.php so
    the hyperlink would be "blah blah blah download.php?id=1234" etc.

    The download.php would also insert the date and time of the download
    into a my sql db.

    I can get this far myself but I am stuck now as how to actually then
    start the download once I've logged it.

    Any ideas?

    Thanks,

    td.
    toedipper Guest

  2. #2

    Default Re: starting a download within php

    > Any ideas?

    First log the download, then:

    http://www.php.net/header

    Simple example:

    <?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');

    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');

    // The PDF source is in original.pdf
    readfile('original.pdf');
    ?>

    Best regards
    Fredrik A. Takle
    Bergen, Norway


    Fredrik Guest

  3. #3

    Default Re: starting a download within php

    Hi td,

    try something like this.

    <?
    /*
    * Change 'CONTENT=6' to however many seconds
    * you want the user to wait to be linked to
    * the file
    *
    * Put this line in between the <head> tags
    */
    echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"6;
    URL=http://link/to/remote_file.zip\">";

    /*
    * put this in the main body after you registered
    * the download in the db
    */
    echo "Please wait while download starts...";
    ?>

    hope this helps,

    adnan


    toedipper wrote: 

    Adnan Guest

  4. #4

    Default Re: starting a download within php

    Adnan said the following on 12/06/2005 12:26: 

    No! Don't do this!

    You have no control over the download (because the user now has a direct
    URL to the file), it adds an unnecessary 6 (or whatever) second delay,
    and it uses "refresh", which isn't a valid HTTP header (although it does
    work on many browsers).


    --
    Oli
    Oli Guest

Similar Threads

  1. lwp-download http://..--how do I use it to download pages?
    By bdy120602@gmail.com in forum PERL Modules
    Replies: 7
    Last Post: June 28th, 04:22 AM
  2. Unable to download trial, download pulled?
    By brandner in forum Macromedia Contribute General Discussion
    Replies: 3
    Last Post: May 14th, 05:00 PM
  3. Replies: 0
    Last Post: September 10th, 04:58 PM
  4. #25471 [NEW]: The PHP Doentation download page does not show any download in Mozilla
    By mahesh dot chandrasekar at icici-infotech dot com in forum PHP Development
    Replies: 0
    Last Post: September 10th, 04:24 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139