asp 如何计算客户端下载了多大的视频
asp 如何计算客户端下载了多大的视频
2012-07-15 16:18
2012-07-15 17:04
2012-07-15 17:07
2012-07-15 22:03
2012-07-15 22:06
2012-07-15 23:01
2012-07-16 18:46
程序代码:
'函数格式 Download(StrFile,NewName)
'功能描述 下载一个已经存的的文件,处理中文不能下载的问题
'应用代码 By HT.Liu
Public FunctIon Download(StrFile,NewName)
Dim StrFIlename,ALLOW_FILE_EXT,FileExt,Fso,IntFIlelength,Upload,S,TotalSize,offset,f,ChunkSize,strChunk
StrFIlename = Server.MapPath(strFile)
ALLOW_FILE_EXT = ",ASP,ASA,ASPX,ASAX,MDB,PHP,JSP,SHTML,HTML,HTM,TV,DATA,Config,INI,VBS,JS,"
FileExt=MId(StrFIlename,InStrRev(StrFIleName, ".")+1)
Response.Buffer=True
Response.Clear
If InStr("," & ALLOW_FILE_EXT & ",", "," & FileExt & ",") > 0 Then
Download = "不允许下载此文件格式."
Exit Function
End If
Set Fso=Server.CreateObject("ScrIptIng.FIleSystemObJect")
If Not Fso.FIleExists(StrFIleName) Then
Download = "下载的文件不存在."
Exit Function
End If
Set F=Fso.GetFIle(StrFIlename)
IntFIlelength=F.SIze
If Err Then
Download = "该文件数据不完整或许已损坏."
Exit Function
End If
Set S=Server.CreateObject("ADODB.Stream")
S.Type = 1
S.Open
'Response.write StrFIlename
'Response.end
s.LoadFromFIle(StrFIlename)
TotalSize = S.Size
Response.ContentType = "application/x-download; charset=UTF-8"
'Response.ContentType = "application/x-download"
Response.AddHeader "Content-DIsposItIon","attachment; filename="&NewName
Response.AddHeader "Content-Length",IntFilelength
offset = 0
'定义每次请求的下载流字节
ChunkSize = 2*1024*1024
While offset < TotalSize
If (TotalSize - offset < ChunkSize) Then
ChunkSize = TotalSize - offset
End If
strChunk = S.Read(ChunkSize)
'Response.write strChunk
Response.BinaryWrite strChunk
Response.Flush
offset = offset + ChunkSize
Wend
S.Close
Set S = NothIng
Set Fso = Nothing
Call Log_Write("下载文件:"&StrFIlename&"=>"&NewName)
End FunctIon
2012-07-17 19:56