SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Newcastle, England
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need to write a download manager (ASP)

    Hi,

    I need to host a number of files (all .zip's), and want to code my downloads page so that when you click a link to download, it calls a page like download.asp?file=123 or something; this page tracks number of downloads etc., then sends the user the file - pretty much the same way dozens of sites out there do. However, I'd like to make sure the file must be downloaded through this page - I don't want anyone to be able to download it once, check the actual location of the file in the download box and link straight to it from their own site.

    Is this possible? I had thought it may be possible to hold the files in a folder outside the web server root, so that you can't get to it in a browser - then on the download page send them the file. However I'm not sure if this is possible (I think I've seen it done in PHP but don't know exactly how it was coded; the download page set some headers then used the readfile() function to send it I think).

    Alternatively, I thought I could again store the files outside the web server root, and the download.asp page could copy the file to a temporary location. The user would then download this temporary file, and once he'd finished it would be deleted. So far so good, but how can I easily have the file deleted from the temporary location when the download is finished (i.e. how do I know the user has completed the download)?

    Are either of these methods feasible? If so, can you explain the areas I'm hazy on (in the first, sending a file outside the server root to the user; in the second, deleting the file once it's been downloaded). Or is there an alternative method (there are probably dozens).

    Thanks in advance for any help, I'm grateful for any advice you can give me .
    Nick Wilson [ - email - ]

  2. #2
    SitePoint Wizard big_al's Avatar
    Join Date
    May 2000
    Location
    Victoria, Australia
    Posts
    1,661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    well the counter would be fairly easy, either use a database or a text file and just increment the count by one.

    As for not allowing the user to do a direct link to that file, you could use a Querystring i.e www.site.com/donwloads/?dld=114
    you could then test whether the person has come from a page from you site using the Request.ServerVariable("HTTP_REFERER") object and throw an error message if the referer is not from your site.

    Hope this has helped
    .NET Code Monkey

  3. #3
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Newcastle, England
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply

    Yeah, I'm happy enough writing the counter etc. and checking the referer in the download page. But when someone downloads the file via this page, they'll still see the address of the actual file in the download box won't they? So they could provide a link on their own site which went directly to this file, rather than the download page, and get around it like that. The download.asp page can only check the referer for a call to itself, not for a call straight to the .zip file.

    As I say, I thought I could store the .zip file outside of the web server's root, so that it couldn't be linked to in this manner - but I don't know how to get the download.asp page to actually download that file? Surely I can't just use Response.Redirect to go to a file outside the server's root, can I? In PHP the solution is a function which reads the contents of a file and outputs it to the browser - is this the kind of thing I should be doing? It's probably dead simple, but I can't test any obvious things right now (I have no access to a web server at the moment).

    Hope that's a little clearer, I'm afraid I'm not very good at explaining problems like this

    Cheers
    Nick Wilson [ - email - ]


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
  •