I need help with file downloads

Discussion in 'PHP' started by cckid, Sep 7, 2007.

  1. #1
    Hi everyone,
    I have this form that users have to fill out in order to get to a free download.
    Instead of just sending them to www.domain.com/file.pdf, I would like to create a temporary fie with an expiring name so that they can't just download the file anytime they want.
    So in short, this is what I want:
    User signs up
    The file is created, email is sent.
    The user gets email with download link.
    The user downloads the file.
    The file and link are destroyed.

    How can I accomplish this?
    Thanks so much for the helps!
    :D
     
    cckid, Sep 7, 2007 IP
  2. amf-flt

    amf-flt Active Member

    Messages:
    100
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    I think you may be going about this wrong. Instead of creating a temp file (unless you absolutely have to because the file is dynamically generated), send them a link with a random value that your code translates into the file you want to download and send it to them by streaming the file (with the proper headers preceding the stream, so that the file comes out like a stream and not like junky HTML).
     
    amf-flt, Sep 7, 2007 IP
  3. cckid

    cckid Peon

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks amf-flt-
    I think you may be right about me going about it wrong. :)
    could you expand a little bit about the "send them a link with a random value that your code translates into the file you want to download and send it to them by streaming the file (with the proper headers preceding the stream, so that the file comes out like a stream and not like junky HTML)." part?
    Thanks!
     
    cckid, Sep 9, 2007 IP
  4. cckid

    cckid Peon

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i'm still stuck on this - could someone elaborate a little bit to help me figure this out? :) THANK!!
     
    cckid, Sep 17, 2007 IP
  5. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #5
    When someone wants to download (after payment I assume) generate them a random number and stick it in a database. After doing this on the server, send the downloader an email with a link to get the file. When the downloaded clicks the link, delete the record from the database and give them access to the file.

    By doing this, next time they click the link in the email (or try to access the page directly) the database will not contain a code and the process will error out however you want it to.

    This is a pretty simple process but would contain a fair amount of custom coding for your server (db setup, mail to user, etc.) so I doubt you will be getting code in this thread ... but someone might proove me wrong.
     
    ErectADirectory, Sep 17, 2007 IP
  6. Aron Schatz

    Aron Schatz Peon

    Messages:
    201
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Tackling it in Pseudo code!

    First you need the file you want to download... File1.jpg

    Now you have someone that wants to download the file, but you want to make sure they do something first...

    Never offer the file directly. Always offer it 'through' PHP by dumping the file into the browser.

    You give the user a download link like www.whatever.com/download.php?id=ASsdva4124ABG and that crazy id (or any id) will have a record in the database pointing to the file.

    All you need to do is mark the record as used and dump the file.
     
    Aron Schatz, Sep 17, 2007 IP
  7. cckid

    cckid Peon

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks guys, I appreciate it!
    ErectADirectory: I was looking for some help with the logic here and that's what I got from you guys. Thanks again! Will get to work on this bit soon!!
     
    cckid, Sep 18, 2007 IP