搜索
您的当前位置:首页正文

AspUpload组件上传大文件

来源:知库网


AspUpload组件上传大文件

最近闲来无事,给公司做了个内部娱乐网站(ASP的),用的服务器是win2003+IIS6.0,因为是内部的,足够用了。其中一个功能是在线影院,提供在线观看、下载功能,同时也提供上传功能。

在上传大文件时,稍微费了些时间。

1.首先要修改 metabase.xml 文件,因为IIS6.0默认上传限制是20K。

首先停止Internet 信息服务(IIS)的internet服务;

找到文件c:/windows/system32/inetsrv/metabase.xml,用“记事本”打开该文件,修改AspMaxRequestEntityAllowed。

好像IIS最大支持的也就1G吧,因为尝试把这个值设的非常大时,这个属性就会在文件中消失。

2. 下载安装Aspupload

3. 为了防止上传超时,在程序里要加上这么一句: Server.ScriptTimeout=9999

4. 下面就是代码了:

(1) bar.asp

<%@EnableSessionState=False%>

<%

Response.Expires = -1

PID = Request(\"PID\")

TimeO = Request(\"to\")

Set UploadProgress = Server.CreateObject(\"Persits.UploadProgress\")

format = \"

正在上传,请耐心等

待...


%T%t%B3%T 速度:(%S/秒) 估计剩余时间:%R %r%U / %V(%P)%l%t\"

bar_content = UploadProgress.FormatProgress(PID, TimeO, \"#00007F\

If \"\" = bar_content Then

%>

Upload Finished

<%

Else ' Not finished yet

%>

Response.Write Request.ServerVariables(\"URL\")

Response.Write \"?to=\" & TimeO & \"&PID=\" & PID %>\">

Uploading Files...

<% = bar_content %>

<% End If %>

(2) fileconfig.asp

<%

Dim UploadFilePath,UploadLimitSize,NotAllowfileext,BrowerFilePath

UploadFilePath = year(now)&\"_\"&month(now)&\"_\"&day(now)&\"/\"

'文件上传路径

BrowerFilePath = \"/\"

UploadLimitSize = 1024*50 '50M

'最大上传文件大小,单位为K

NotAllowfileext

\"asp|cer|cdx|asa|htw|ida|idq|shtm|shtml|stm|printer|cgi|php|php4|cfm|aspx\"

=

'不可以上传的文件类型

function CanUpload(Fileurl)

Fileurl = lcase(\"|\"& Mid(Fileurl, InstrRev(Fileurl, \".\") + 1)& \"|\")

NotAllowfileextstr = \"|\"&NotAllowfileext&\"|\"

if instr(NotAllowfileextstr,Fileurl)>0 then

CanUpload = false

else

CanUpload = true

end if

end function

Function CreateFolder(Filepath)

Dim fso, f

on error resume next

Set fso = CreateObject(\"Scripting.FileSystemObject\")

if not fso.FolderExists(Filepath) then

Set f = fso.CreateFolder(Filepath)

set f = Nothing

end if

set fso = Nothing

End Function

%>

(3) framebar.asp

<%@EnableSessionState=False%>

<% Response.Expires = -1 %>

正在上传............

&

(4) uploadfile.asp

Upload -51windows.Net

<%

On Error Resume Next

Server.ScriptTimeOut=999999

if request(\"act\")=\"upload\" then

dim folder,savepath

savepath=Server.MapPath(UploadFilePath)

CreateFolder(savepath)

Set Upload=Server.CreateObject(\"Persits.Upload\")

Upload.SetMaxSize UploadLimitSize*1024, True

Upload.OverwriteFiles = false

if Request.QueryString(\"PID\") = \"\" then

Upload.ProgressID=\"010D60EB00C5AA4B\"

else

Upload.ProgressID=Request.QueryString(\"PID\")

end if

Count=Upload.Save(savepath)

If Err.Number <> 0 Then

Response.Write \"

出现错误: \" & Err.Number & \"、\" & Err.Description &\"重新

上传

\"

End If

If Err.Number = 8 Then

Response.Write \"

你上传的文件超过限制(\"& UploadLimitSize/1024 &\"M)重新上传
\"

response.end

end if

dim inputname

dim size,rs_upfile

For Each File in Upload.Files

if not CanUpload(File.ext) then

File.Delete

response.write \"

\"&file.filename &\"(\"& file.size &\") 格式不正确!重新上传

\"

else

dim NewName

NewName = year(now) & \"-\" & month(now) & \"-\" & day(now) & \"-\" & hour(now) & \"-\" & minute(now) & \"-\" & second(now) & File.ext

File.Move savepath & \"/\" & NewName

response.write \"

上传成功\"%>重新上传
<%

end if

next

else

%>

<%

dim SPid,PID,barref

Set UploadProgress = Server.CreateObject(\"Persits.UploadProgress\")

SPid = UploadProgress.CreateProgressID()

PID = \"PID=\" & SPid

barref = \"framebar.asp?to=10&\" & PID

%>

&act=upload\" OnSubmit=\"return ShowProgress();\">

<%end if%>

这样,访问uploadfile.asp,就能实现上传了。

因篇幅问题不能全部显示,请点此查看更多更全内容

Top