Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 17th, 2004, 04:36 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default File download counting

I have a asp download script ( download.asp ) which holds all the links to my files... When a user clicks a link to download a file the download.asp is meant to record the count in the mydownload.mdb
But is looks like it is missing from the script.

I have tried to contact the user that made the script but the email address is unknown....

I'm only new to ASP and would like to know how to add this in my download.asp

This is what the URL looks like when a user downloads a file

http://www.mysite/download.asp?downloadID=17

Can someone help me with this please...

you can download the script from here

http://www.sbnz.net.nz/download.zip

Cheers
Shane

shanebl@sbnz.net.nz

  #2 (permalink)  
Old September 18th, 2004, 01:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi there,

The following function lets the user download the file. Use this function in a separate include file and call this function to force popup window for user to download the file to client machine.
Code:
<% 
function downloadFile(strFile)
' make sure you are on the latest MDAC version for this to work
' -------------------------------------------------------------

' get full path of specified file
'strFilename = server.MapPath(strFile)
strFilename = server.MapPath(Session("downloadPath") & strFile)

' clear the buffer
Response.Buffer = True
Response.Clear

' create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open

' set as binary
s.Type = 1

' load in the file
on error resume next

' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
    Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
    Response.End
end if

' get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size

s.LoadFromFile(strFilename)
if err then
    Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
    Response.End
end if

' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"

' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush

' tidy up
s.Close
Set s = Nothing

end function
%>
Just before calling this function, you should update the database and increment the DownloadCount field by 1
Code:
' Opening record set with a adOpenStatic cursor (the 3) and in UPDATE mode (the 3)
rsDC.Open cmdDC, , 3, 3
rsDC("DownLoadCount") = rsDC("DownLoadCount") + 1
rsDC.Update

' the following line calls the Download File function
call downloadFile(replace(replace(fileName,"\",""),"/","")
This should have given you an idea of how to go about.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Download. rupen ASP.NET 1.x and 2.0 Application Design 4 February 23rd, 2008 08:43 AM
Download File Muhammad Zeeshan ASP.NET 2.0 Professional 0 October 24th, 2007 12:51 AM
Smaller download/single download file available jminatel BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 November 21st, 2005 11:10 AM
Force A File To Download harpua Classic ASP Basics 6 July 26th, 2004 01:06 PM
File download problem sandeep_chalke .NET Web Services 0 June 24th, 2004 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.