|
La Communauté Webmaster 
| Pages: [1] |
 |
|
|
|
Auteur |
Sujet: compteur de téléchargement? (Lu 1716 fois) |
|
 |
compteur de téléchargement?
« sur: le 03-10-2003 a 09:57:26 » |
|
|
|
|
|
|
 |
Re:compteur de téléchargement?
« Répondre #1 sur: le 04-10-2003 a 09:44:47 » |
|
Netah
Modérateur Global
    
Hors-Ligne
Sexe: 
Messages: 1256

ZoneB.org
|
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.
<% ' 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 :
<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>
|
| |
skalae.fr - Stages photo - Blog Webmaster - Twitter TLS |
|
|
 |
Re:compteur de téléchargement?
« Répondre #2 sur: le 04-10-2003 a 12:50:58 » |
|
|
|
|
| Pages:
[1] |
|
|
|
| |
|
|