asp script of download statistic

Discussion in 'C#' started by justinlorder, Mar 23, 2009.

  1. #1
    Hello, Gurus .
    I upload my product catalog to one of my ecommerce site .
    I would like to trace how many times my catalog had been download .

    At present, my site is using asp scripts .
    Are there any asp scripts that can help me .
    I appreciate your help . thanks .
    (PS. are there any php version of the scripts too ?)
     
    justinlorder, Mar 23, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    you could use something simple like: (download.asp):

    
    <%
    Dim fso, f, cnt
    
    On Error Resume Next
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile(Server.MapPath("downloads.txt"))
    cnt = f.ReadLine
    cnt = cnt + 1
    f.Close
    
    Set f = fso.OpenTextFile(Server.MapPath("downloads.txt"), 2, True)
    f.WriteLine cnt
    f.Close
    
    Set f = Nothing
    Set fso = Nothing
    
    Response.Redirect "catalog.pdf"
    %>
    
    Code (markup):
    This would record the number of hits in a file 'downloads.txt'. You would then link to the file like:
    
    <a href="download.asp">View Catalog</a>
    
    Code (markup):
     
    camjohnson95, Mar 24, 2009 IP
  3. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #3
    camjohnson95
    Thanks for your feedback .
    So I can change the following code
    Response.Redirect "catalog.pdf" to "catalog.zip" or other file format .
    The catalog.pdf/catalog.zip must be on the same direct of download.asp . Am I right ?
     
    justinlorder, Mar 24, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    yep,
    well it doesnt have to be, but with that code it would. and downloads.txt would also be in the same directory.
    come to think of it:
    
    Response.Redirect Server.MapPath("catalog.zip")
    
    Code (markup):
    for that last line might be better.

    If you wanted catalog in a different directory a / in front of the file name(catalog.zip) will bring it back to the root directory. so you could go from there.
     
    camjohnson95, Mar 24, 2009 IP
  5. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hello, camjohnson95
    I upload the scripts to my site .
    I can download the catalog.zip .
    But the count doesn't work .
    (I set initail number 1 to download.txt , but I test to download the file and the count doesn't work. )
     
    justinlorder, Mar 24, 2009 IP
  6. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #6
    just note that the filename I have used is 'downloads.txt' with an 's' on the end.
    make sure that your refresh downloads.txt when viewing it too ensure it is not the cached version of the file.
     
    camjohnson95, Mar 24, 2009 IP
  7. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #7
    camjohnson95 .
    Yes, the script works perfect . I mistook downloads.txt and download.txt .
    Thanks .
     
    justinlorder, Mar 28, 2009 IP