SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2001
    Location
    Russia
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to know - how many times a file has been downloaded ?

    I know how to count the number a link was clicked.
    But I want to know how many times
    a file has been completely downloaded.
    Is it possible?

    Thank you.
    Regards,
    Alexander Saprykin
    http://www16.brinkster.com/saprykin

  2. #2
    SitePoint Member
    Join Date
    Dec 2001
    Location
    UK
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think there is a way to do this, as you'd need to get a response from the user as and when he's downloaded the file. Most sites probably do what you've already specified, by the amount of times a download link was clicked.

    The only way I can see how you can do this, if you make your own software application which is specific for downloads from your site. And once, a download has been completed in this software, a response is sent to your web server and it updates the database/text file by 1.

    Maybe someone else knows the answer.

  3. #3
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have this kind of system on a site I run. The following happens:

    1. User clicks like to download & file to download it included in the URL as a querystring (as in ASP), this link doesn't take them to the file but to another page.
    2. Page takes the file name from the querystring and then checks the database to see if it is already in it. If the filename is, it increments the number of times it been downloaded by one, if not, adds the filename into the database.
    3. Redirect user to the file.

    As you can see, I;ve broken it down to three east steps, thats how easy it is.

    I haven't included an example of the code, but as it you cutecode, I would imagine that it's in ASP. If you would like the code, let me know and I'll post it.


  4. #4
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the way i understand your question is that you want to know if a user has completely downloaded a file (meaning they weren't disconnected or cancelled).

    i'm not 100% sure of this but you could check the web log for requests for the specified file and check the row(s) in question for the number of bytes sent/received and compare that to the size of the file. i can already think of several stumbling blocks that you might run into so this method might not be that great. maybe it'll help you though.



    another idea would be to have the link go to an ASP page (or other scripting engine i suppose, but i assume asp 3.0 features here) that opens the file and actually pumps the file to the user by opening it and reading and sending its content, instead of them downloading the file directly; while periodically checking the IsClientConnected property to see if they're still there. then at the end if you make it to the end of the script and they're still connected, you'd know they downloaded the whole thing. the big downside to this is that it would be a lot less effecient than if they had just accessed it directly. if you use this, don't forget to increase your script timeout value to something huge, otherwise it'll probably always timeout. setting the ContentType would also be important. if you can get the script to send them the file, without a lot of overhead, this may be a decent solution. perhaps using the server.execute command to the file in question (if its not a script or executable) would just send the contents of the file to the user and then pass control back to your script. i'd give that a try. and if you do, let us know if it works.

    if you're not using ASP, then maybe your scripting language has similar functionality, or perhaps you should think about changing.
    Last edited by crowdozer; Jan 15, 2002 at 16:27.

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2001
    Location
    Russia
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, guys.
    Thank you for all your replies.
    I'm using ASP.
    I implemented my script as dhtmlgod suggested.

    Code:
    <%@ Language=VBScript %>
    <!-- #INCLUDE FILE="../config.asp"-->
    <% Response.Expires = -1000 
    Response.Buffer = True 'Buffers the content so our Response.Redirect will work
    id = request.querystring("id")
    if id="" then ShowError
    set conn = DBconn
    set rs=conn.execute("sp_driver_id " & id)
    if rs.eof then ShowError
    conn.execute("sp_driver_downloads_incr " & id)
    response.redirect rs.fields("driver_path")
    %>
    After thinking it over, I think that it is impossible to know if a file
    has been completely downloaded. Since softwares like FlashGet, ReGet etc
    can resume downloading even after connection is lost.
    And they can resume download even 2 years later.
    Regards,
    Alexander Saprykin
    http://www16.brinkster.com/saprykin

  6. #6
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    insted of ending with response.redirect, you could do this...
    [vbs]
    if rs.eof then ShowError

    Response.ContentType = "" ' youll have to programmatically fill this

    server.execute rs.fields("driver_path") ' will send them the file and then give control back to your script
    ' (may not work correctly for executables and scripts.)

    if Response.IsClientConnected then
    ' they're still connected, therefore they downloaded the whole file.
    conn.execute("sp_driver_downloads_incr " & id)

    else
    ' they disconnected
    end if

    [/vbs]


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
  •