Forum-webmaster
Technique - programmation => Asp / Asp.net / IIS => Message commencé par: OVM- le le 03-10-2003 a 09:57:26

Titre: compteur de téléchargement?
Posté par: OVM- le le 03-10-2003 a 09:57:26

;DBonjour
je cherche comment je pourrais installer un compteur de téléchargement sur mon site est j'aurais besoin d'un peut d'aide ???alors help je compte sur vous ;)

Titre: Re:compteur de téléchargement?
Posté par: Netah le le 04-10-2003 a 09:44:47

Ce code src n'est pas garanti sans erreur, je suis en train de le refaire pour accepter plusieurs types de fichier. Le modifier pour un seul type n'est pas tres difficile.
Le download est la partie la plus complexe de ce script. Le compteur est classique avec une variable application que l'on incrémente.

Code:

<%
'               Infos...               //
'/////////////////////////////////////////////////////////////////////////////////////////////////
'Used by ZoneB.org
'uses: Download.asp?file=File.exe

'/////////////////////////////////////////////////////////////////////////////////////////////////
'               Config...               //
'/////////////////////////////////////////////////////////////////////////////////////////////////

   method = 1
BasePath = Request.ServerVariables("APPL_PHYSICAL_PATH")
FileName = request.QueryString("file")
FileExt = LCase(Right(FileName, 3))

FilePath = BasePath & "a_download\"

Select Case lcase(FileExt)
Case "avi" ContentType = "video/x-msvideo"
Case "mp3" ContentType = "audio/mpeg"
Case "ogg" ContentType = "audio/mpeg"
      Case "mpg" ContentType = "video/mpeg"
Case "wav" ContentType = "audio/wav"
Case "rar" ContentType = "application/x-rar-compressed"
Case "zip" ContentType = "application/x-zip-compressed"
      Case "xls" ContentType = "application/x-msexcel"
      Case "txt" ContentType = "text/plain"
      Case "htm" ContentType = "text/html"
      Case "gif" ContentType = "image/GIF"
      Case "jpg" ContentType = "image/JPEG"
      Case "cdf" ContentType = "application/x-cdf" 'channel
      Case "doc" ContentType = "application/msword"
      Case "ppt" ContentType = "application/vnd.ms-powerpoint"
      Case "exe" ContentType = "application/octet-stream"
Case Else ContentType = FileExt
End Select

call SendFile( FilePath, FileName, ContentType )


'/////////////////////////////////////////////////////////////////////////////////////////////////
'               Download               //
'/////////////////////////////////////////////////////////////////////////////////////////////////

function SendFile( FilePath, FileName, ContentType )
if method = 1 then
if (FilePath = "") or (FileName = "") or (ContentType = "") then
Response.Write("oups!")
Response.End
else
Response.Clear
Dim adoStream
Set adoStream = Server.CreateObject("ADODB.Stream")

      adoStream.Open()
         adoStream.Type = 1
         adoStream.LoadFromFile(FilePath & FileName)
         Response.AddHeader "Content-Disposition", "attachment;filename=" & FileName
         Response.ContentType = ContentType
         Response.BinaryWrite(adoStream.Read())
         adoStream.ConnectionTimeout = 0
         Application("DownloadCounter") = Application("DownloadCounter") + 1
      adoStream.Close
    Set adoStream = Nothing
      Response.End
    end if

else

If FileName <> "" And FilePath <> "" and contentType <> "" then
      Set ObjFso       = CreateObject("Scripting.FileSystemObject")
      'If objFso.FileExists(FilePath & FileNeme) = FALSE Then
      '   Response.write "This file doesn't exist<BR><B> - Please Contact the webmaster.</B><BR><BR>"
      '   Set ObjFso    = Nothing
      '   response.end
      'End If
      Set ObjInfoFile    = ObjFso.GetFile(filePath & FileName)
      Set ObjFile       = ObjFso.OpenTextFile(FilePath & FileName , 1,true)

      Response.ContentType = contentType
      Response.Addheader( "Content-Length", ObjInfoFile.Size )
      Response.Addheader( "Content-Disposition", "attachment; filename=" & FileName )
      Response.Write ObjFile.ReadAll
      Application("DownloadCounter") = Application("DownloadCounter") + 1
      Set ObjFile    = Nothing
      Set ObjFso    = Nothing
      Set ObjInfoFile   = Nothing
   else
      Response.write "Le File n'a pas pu être téléchargé... Erreur dans le lien ?<BR><B> - Merci de retenter <A href=""" & lCase(URLRef) & """>"& lCase(URLRef) &"</A></B><BR><BR>"
      response.Write( FilePath & FileName & ContentType)
   End If
end if
End Function
%>


La variable application est définie dans le global.asa. Voila une partie du miens :

Code:

<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="Server">
Sub application_OnStart
   Application("vis") = 0
   Application("act")=0
   Application("UsersToday") = 0
   Application("PagesToday") = 0
   Application("PagesTotal") = 0
   Application("NewToday") = 1
   Application("DownloadCounter") = 0
   Application("Today") = FormatDateTime(now(),1)
End Sub

Sub session_onstart
   Session.timeOut = 10
   Session("depart")=Now

   Application.lock
      Application("vis") = Application("vis")+1
      Application("act") = Application("act") + 1
nDate = FormatDateTime(now(),1)
if Application("Today") = nDate then
Application("UsersToday")=Application("UsersToday")+1
else
Application("Today") = nDate
Application("UsersToday") = 1
Application("PagesToday") = 1
end if
   Application.UnLock
End Sub

Sub session_onEnd
Application.lock
    Application("Act")=Application("Act")-1
Application.unlock
End Sub
</SCRIPT>

Titre: Re:compteur de téléchargement?
Posté par: OVM- le le 04-10-2003 a 12:50:58

ok je vais tester je te dirait quoi merci


Forum-webmaster | Actionné par YaBB SE
© 2001-2003, YaBB SE Dev Team. Tous droits réservés.