
======================================================================================

1.ʹ޾ϴ˵

======================================================================================

main.asp磺

<form name="form1" method="post" action="upload.asp" enctype="multipart/form-data">
<input type=file name="img1"><br>
<input type=submit name="submit" value="ύ">
</form>

'-------------------------------------------------------------------------------

upload.asp磺

<!--#include file="inc/AspBox/Cls_AB.asp" -->
<%
dim upfile
ab.use "up" : ab.up.use "upfile"
'Set upfile = new cls_ab_up_upfile
Set upfile = ab.up.upfile

upfile.AllowExt="jpg;jpeg;gif;png;" 'ϴ͵İ
'ȡϴ,ϴ10M 㷽Ϊ 10240000/1000000=10.24M
upfile.GetData(10240000)

'оǷ
if upfile.isErr then
  select case upfile.err
    case 1
      Response.Write "ûϴ"
    case 2
      Response.Write "ϴļ,10M"
  end select
else
  'ִбļ
  dim oFile,SavePath,SaveFilename
  SavePath = "c:\" 'ļ·
  set oFile=upfile.file("img1")
  upfile.SaveToFile "img1", SavePath & oFile.filename
  'SaveFilename = upfile.AutoSave("img1",SavePath) 'ִԶļ룬SaveFilenameΪļ(Զ)
  if upfile.iserr then 
	Response.Write upfile.errmessage & "<br>"
  else
	Response.Write "ϴɹ·"& SavePath & oFile.FileName &"<br>"
	'Response.Write "ϴɹ·"& SavePath & SaveFilename &"<br>"
  end if
end if
set upfile=nothing
%>

======================================================================================

2.ʹûHTTPϴ˵

======================================================================================

main.asp磺

<% dim uppath : uppath = "./upload" %>
<form name="uploadform" method="post"
 action="upload.asp?action=SaveUploadFile&filepath=<%=uppath%>" enctype="multipart/form-data">
ϴļ<br>
<input type="file" name="file1"><br>
<input type="file" name="file2"><br>
<input type="file" name="file3"><br>
<input type="submit" name="Submit" value="ȷϴ" class=""/>
<input type="hidden" name="filepath" value="<%=uppath%>" size="60">
</form>

'-------------------------------------------------------------------------------

upload.asp磺

<!--#include file="inc/AspBox/Cls_AB.asp" -->
<%
If Request.QueryString("action") = "SaveUploadFile" then
	Call SaveUploadFile 'ϴ
End If

Function SaveUploadFile
	On Error Resume Next '
	Response.Buffer = True
	Randomize
	Dim RanNum,Fso
	RanNum = Int(90000*rnd)+10000
	Set Fso = Server.CreateObject("Scripting.FileSystemObject")
	Const filetype = ".bmp.gif.jpg.png.rar.zip.7z" 'ϴļ
    Const MaxSize = 10240000 'ļС 10M
    Dim upload,oFile,formName,formPath,oldfilename,newfilename,temp,fileExt
	ab.use "up" : ab.up.use "u5x"
	'set upload = new cls_ab_up_u5x
	set upload = ab.up.u5x
	upload.init() 'ʼִк,ǰ!!
    If upload.Form("filepath")<>"" Then
		formPath = Server.mappath(upload.Form("filepath"))
		If Right(formPath, 1)<>"\" Then formPath = formPath&"\"
		If fso.FolderExists(formPath)<>true Then
			fso.CreateFolder(formPath)
		End If
		Dim isUploaded : isUploaded = True 'Ƿϴɹ
		For Each formName in upload.objFile
			Dim iUploaded : iUploaded = True
			Set oFile = upload.File(formName)
			If oFile.FileName="" Then
				iUploaded = True
			Else
				temp = Split(oFile.FileName, ".")
				fileExt = temp(UBound(temp))
				If InStr(1, filetype, LCase(fileExt))>0 Then
					oldfilename = Split(oFile.FileName,"\")(UBound(Split(oFile.FileName,"\"))) 'ԭ
					newfilename = RanNum&"."&Split(oldfilename,".")(UBound(Split(oldfilename,"."))) 'ļ
					If oFile.FileSize>0 And (oFile.FileSize<MaxSize) Then
						iUploaded = (iUploaded and oFile.SaveAs(formPath&oldfilename))
						If Err<>0 Then
							iUploaded = False
							Response.Write "<script>alert(""ϴ̳"");history.go(-1);</script>"
							Err.Clear
							Response.End
						End If
					Else
						iUploaded = False
					End If
				Else
					iUploaded = False
				End If
			End If
			isUploaded = isUploaded and iUploaded
			Set oFile = Nothing
		Next
		IF isUploaded=True Then
			Response.Write("<script>alert(""ϴɹ"");history.go(-1);</script>")
		Else
			Response.Write("<script>alert(""ϴʧܣ"");history.go(-1);</script>")
		End IF
	Else
		Response.Write("<script>history.go(-1);</script>")
	End If
    Set upload = Nothing
End Function
%>

======================================================================================

3.ʹð˵

======================================================================================

form.html磺

ļϴ<br />
<form action="upload.asp" method="post" enctype="multipart/form-data">
ļ <input type="file" name="file1" /> <input type="submit" value="ϴ" />
</form>

'-------------------------------------------------------------------------------

upload.asp磺

<!--#include file="inc/AspBox/Cls_AB.asp" -->
<%
Dim Upload
'---------------------------
'ʵ
ab.use "up" : ab.up.use "an"
'Set Upload = New Cls_AB_Up_An
Set Upload = AB.Up.An

'õļϴ,ֽڼƣĬΪ
Upload.SingleSize = 2 * 1024 * 1024 '2M

'ϴ,ֽڼƣĬΪ
Upload.MaxSize = 2 * 1024 * 1024 '2M

'úϷչ,|ָ,ԴСд,"jpg|bmp|jpeg|gif|png",Ϊ"*"
Upload.Exe = "*"

'ı룬ĬΪgb2312
Upload.Charset="gb2312"

'ȡ,ñ
Upload.GetData()
'---------------------------
if upload.ErrorID>0 then
	response.Write upload.Description
else
	dim file,savepath,frm,result,msg
	savepath = "upload"
	for each frm in upload.forms("-1")
		response.Write frm & "=" & upload.forms(frm) & "<br />"
	next
	set file = upload.files("file1")
	if not(file is nothing) then
		result = file.saveToFile(savepath,0,true)
		if result then
			response.Write "ļ'" & file.LocalName & "'ϴɹλ'" & server.MapPath(savepath & "/" & file.filename) & "',ļС" & file.size & "ֽ"
		else
			response.Write file.Exception
		end if
	end if
end if
set upload = nothing
%>