Current location: Hot Scripts Forums » Programming Languages » ASP » Upload and download counting.


Upload and download counting.

Reply
  #1 (permalink)  
Old 08-16-03, 03:16 PM
Arctic Arctic is offline
Wannabe Coder
 
Join Date: Jul 2003
Location: BC, Canada
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Upload and download counting.

I changed my upload and download script. It now writes the file to a database for the upload. How do i make it so when a file is uploaded it writes a record set or something to the database and then displays the total number of uploads on the upload page. I also want to be able to display the number of times each file has bee downloaded beside each file.

Code:

page for uploading action (uploader.asp)
=============================
<%
' Variables
' *********
Dim mySmartUpload
Dim file
Dim oConn
Dim oRs
Dim intCount
Dim curDir
Dim strSQL
Dim rs
intCount=0

' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

' Only allow txt or htm files
' ***************************
mySmartUpload.AllowedFilesList = "zip,exe"

' Deny physical path
' *******************
mySmartUpload.DenyPhysicalPath = True

' Only allow files smaller than 50000 bytes
' *****************************************
mySmartUpload.MaxFileSize = 5120000

' Deny upload if the total fila size is greater than 200000 bytes
' ************************************************** *************
mySmartUpload.TotalMaxFileSize = 5120000

' Upload
' ******
mySmartUpload.Upload

' Connect to the DB
' *****************
Set oConn = Server.CreateObject("ADODB.Connection")
curDir = Server.MapPath("../databases/files.mdb")
oConn.Open "DBQ="& curDir &";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;"

' Open a recordset
' ****************
strSQL = "SELECT FILENAME,FILE FROM TFILES"

Set oRs = Server.CreateObject("ADODB.recordset")
Set oRs.ActiveConnection = oConn
oRs.Source = strSQL
oRs.LockType = 3
oRs.Open

' Select each file
' ****************
For each file In mySmartUpload.Files
' Only if the file exist
' **********************
If not file.IsMissing Then

' Add the current file in a DB field
' **********************************
oRs.AddNew
file.FileToField oRs.Fields("FILE")
oRs("FILENAME") = file.FileName
oRs.Update
intCount = intCount + 1
End If
Next

' Display the number of files uploaded
' ************************************
Response.Write(intCount & " file(s) uploaded.<BR>")

' Destruction
' ***********
oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
%>


Download page (downloader.asp)
========================
<%
' Variables
' *********
Dim mySmartUpload
Dim oConn
Dim strSQL
Dim oRs

' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

' Connect to the DB
' *****************
Set oConn = Server.CreateObject("ADODB.Connection")
curDir = Server.MapPath("../databases/files.mdb")
oConn.Open "DBQ="& curDir &";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;"

' Open a recordset
' ****************
strSQL = "SELECT FILENAME,FILE FROM TFILES"

Set oRs = Server.CreateObject("ADODB.recordset")
Set oRs.ActiveConnection = oConn
oRs.Source = strSQL
oRs.Open


' DownloadField
' *************
mySmartUpload.DownloadField(oRs("FILE"))
' samples with optionnals
' Call mySmartUpload.DownloadFile(oRs("FILE"), "application/x-zip-compressed", "download.zip")
' Call mySmartUpload.DownloadFile(oRs("FILE"), "application/x-zip-compressed", oRs("FILENAME"))

' Destruction
' ***********
oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
%>

Any help would be great. Thanks!
__________________
http://www.streamsearch.ca - Live stream search engine. Find radio stations to listen to and TV channels to watch!

http://www.machonemedia.ca - Mach One Media web development and media services.
Reply With Quote
  #2 (permalink)  
Old 08-16-03, 04:29 PM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
Upload count - Since you have records going into the database for every upload, you can just do a:

Code:
select count(filename) from table
to figure out how many records there are in the table.


To count the downloads, create a column in your table called "downloads". Initially this should be set to 0.

Now, whenever a file is requested, just do something like...

Code:
update table_name set downloads=downloads+1 where filename='filename.zip'
it's pretty straight forward.
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
Reply With Quote
  #3 (permalink)  
Old 08-16-03, 10:44 PM
Arctic Arctic is offline
Wannabe Coder
 
Join Date: Jul 2003
Location: BC, Canada
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Im not sure about where to put these code lines. I tried

' Display the number of files uploaded
' ************************************
Response.Write(intCount & " file(s) uploaded.<BR>")

fileCount = select count(filename) from TFiles

I dont know a lot about asp and was just going by other things i have seen, like.. 'fileCount = select count....' Im not sure if this is write but i want to be able to display the number of total files uploaded on the main upload page (the one that is just mainly HTML, with the upload form). The way i tried it was by putting 'fileCount = select count...' so i could make a <% fileCount %> on the main upload page with the form for uploading. But it didnt work. Can show me where to put the code lines and what '<% fileCount %>' to put so the number of total uploads goes to main page with the upload form. And help with where to put the download code lines you told me would be great too. Thanks
__________________
http://www.streamsearch.ca - Live stream search engine. Find radio stations to listen to and TV channels to watch!

http://www.machonemedia.ca - Mach One Media web development and media services.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a download system Furton Script Requests 0 09-10-03 02:48 PM
List images and zip before download jaimexyz Script Requests 0 09-01-03 03:01 PM
File download upload Ole Nygaard PHP 15 08-25-03 08:22 AM
Upload / Download / View Wraith Script Requests 1 08-24-03 07:56 AM
php Mirror upload and download software TAK PHP 1 06-25-03 10:31 AM


All times are GMT -5. The time now is 03:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.