Today we are going to see how we can keep track of downloaded files in a web site.
We normally link files with an hyperlink. The trick in this case is to pass the file information to another ASP page and then - after "taking note" of the relevant information - initiate the download.
Ready to see the code? Follow me...
Ok folks, this time things are very easy.
We need to create hyperlinks to files like:
The above code will simply redirect the user to another page (dwnchk.asp). At the same time we are passing the information needed to complete our "evil" plan: keep track of what is downloaded!
<a href="dwnchk.asp?filename=test.zip">Download test.zip</a>
When the dwnchk.asp page is loaded we just need to get the filename, pass it to a DB or whatever we prefer. For example we can increase a counter on a db: if the file name is already there, increase a counter by one, if not create a new record and set the counter to one.
All the above is easily done... if you read The web thought you can find all you need in order to create suitable queries.
When the db update is done, we can initiate the download with something like:
Easy, isn't it?
Response.ContentType = "application/x-zip-compressed"
This is really a simple solution as you can see... Just one more thing! Remember: don't write any HTML code in dwnchk.asp.