日期:2014-01-25 浏览次数:21067 次
[FileName]:upload.asp
[Code]:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#i nclude virtual="upload.inc"-->
<%
If Request.ServerVariables("REQUEST_METHOD")="POST" then
'表单提交执行
CONST upFileSize=100 '文件大小限制,单位:KB
CONST upFileType=".gif.jpg.jpeg" '文件类型限制,可根据需要修改
CONST targetPath="/publish/images/" '以网站为根目录的文件存放路径,以"/"结束
dim upload,thisFile,formName,iCount
set upload=new upload_5xSoft ''建立上传对象
Flag=True '初始化文件上传标识
for each formName in upload.ifile '列出上传文件的所有参数
set thisFile=upload.ifile(formName) '生成一个文件对象
If thisfile.filesize=0 then
Flag=False
Msg="请选择你要上传的文件。"
CALL showErr(Msg)
end if
if thisfile.filesize>upFileSize*1024 then
Flag=False
Msg="文件大小超过了限制。"
CALL showErr(Msg)
end if
if Instr(upFileType,GetExtendName(thisfile.FileName))=0 then
Flag=False
Msg="文件格式不符合要求。"
CALL showErr(Msg)
end if
If Flag then
'创建临时上传文件夹
tempPath="/publish/images/"&Session.SessionID&"/"
set FSO= CreateObject("Scripting.FileSystemObject")
If NOT FSO.FolderExists(Server.MapPath(tempPath)) then
'文件夹未存在则创建
FSO.CreateFolder(Server.MapPath(tempPath))
set FSO=Nothing
End if
'执行文件上传操作
setFileName=now() '获取当前时间作为文件名
setFileName=Replace(setFileName,"-","") '去除日期格式符"-"
setFileName=Replace(setFileName," ","") '去除空格
setFileName=Replace(setFileName,":","")&GetExtendName(thisfile.FileName) '去除时间格式符":"及添加文件扩展名
thisfile.SaveAs Server.mappath(tempPath&setFileName)
End if
Next
CALL resultTip()
Response.End()
End if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<style type="text/css">
<!--
body {
font-size: 12px;
}
-->
</style>
</head>
<body leftmargin="0" topmargin="0">
<form action="" method="post" enctype="multipart/form-data" name="frm_pic">
<input type="file" name="file">
<input type="submit" name="Submit" value="上传">
</form>
1、只能上传<%=upFileType%>格式的图片<br>
2、图片大小请在<%=upFileSize%>K以内<br>
3、请对您所上传的图片内容负责
</body>
</html>
<%
Sub resultTip()
'本过程用于显示上传操作结果
Response.Write("<html><head>")
Response.Write("<meta http-equiv=Content-Type content=text/html; charset=gb2312>")
Response.Write("<title></title></head>")
Response.Write("<script>parent.frm_publish.P_Image.value='"&setFileName&"'</script>") '把文件名传递至父文件的隐藏表单控件
Response.Write("<body leftmargin=0 topmargin=0>")
Response.Write("<table><tr><td><font color=red><b>图片上传成功</b></font></td>