<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include FILE="upload.inc"-->
<!--#include FILE="show_error.asp"-->
<%
dim work_name
work_name=trim(request.querystring("work_name"))
'过滤字符
Dim filesext
filesext="gif,jpg,jpeg,bmp,png"
If Request.QueryString("action")="Upload" Then
Server.ScriptTimeOut=999999'要是你的论坛支持上传的文件比较大,就必须设置。
'定义变量
dim Forumupload,ranNum,success
dim formName,formPath,filename,file_name,fileExt,Filesize,F_Type
dim DownloadID,rs
dim uploadpath
upload_0(work_name)
'===========================无组件上传============================
function upload_0(str1)
dim upload,file
set upload=new UpFile_Class ''建立上传对象
upload.GetDate (2000000) '取得上传数据,不限大小
if upload.err > 0 then
select case upload.err
case 1
call error("请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]")
call Iserror()
'response.end
case 2
call error("文件大小超过了限制 2000K [ <a href=# onclick=history.go(-1)>重新上传</a> ]")
call Iserror()
'response.end
end select
response.end
else
formPath=upload.form("filepath")
'在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
fileExt=lcase(file.FileExt)
'判断文件类型
if lcase(fileEXT)="asp" and lcase(fileEXT)="asa" and lcase(fileEXT)="aspx" then
CheckFileExt(fileEXT)=false
end if
if CheckFileExt(fileEXT)=false then
call error("文件格式不正确 [ <a href=# onclick=history.go(-1)>重新上传</a> ]")
Call Iserror()
response.end
end if
'付值变量
randomize
ranNum=int(90000*rnd)+10000
'F_Type=CheckFiletype(fileEXT)
file_name=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
'work_name为传递过来的该次作业的名称
file_name=session("student_num_name") & "_" & cstr(str1) & "_" & file_name
filename=file_name&"."&fileExt
filename=formPath&filename
Filesize=file.FileSize
'记录文件
if Filesize>0 then '如果 FileSize > 0 说明有文件数据
file.SaveToFile Server.mappath(FileName) ''执行上传文件
'call checksave() '记录文件
end if
set file=nothing
next
end if
set upload=nothing
success="文件上传成功!"
end function
'判断文件类型是否合格
Private Function CheckFileExt (fileEXT)
dim Forumupload
Forumupload=split(filesext,",")
for i=0 to ubound(Forumupload)
if lcase(fileEXT)=lcase(trim(Forumupload(i))) then
CheckFileExt=true
exit Function
else
CheckFileExt=false
end if
next
End Function
'判断文件类型:0=其它,1=图片,2=FLASH,3=音乐,4=电影
Private Function CheckFiletype(fileEXT)
dim upFiletype
dim FilePic,FileVedio,FileSoft,FileFlash,FileMusic
fileEXT=lcase(replace(fileExt,".",""))
Select Case LCase(fileEXT)
Case "gif", "jpg", "jpeg","png","bmp","tif","iff"
CheckFiletype=1
Case "swf", "swi"
CheckFiletype=2
Case "mid", "wav", "mp3","rmi","cda"
CheckFiletype=3
Case "avi", "mpg", "mpeg","ra","ram","wov","asf"
CheckFiletype=4
Case Else
CheckFiletype=0
End Select
end function
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=work_name%></title>
<link href="eric.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="?action=Upload" method="post" enctype="multipart/form-data" name="upload">
<table width="600" border="0" align="center" cellpadding="4" cellspacing="1" id="table_01">
<tr>
<td width="108" class="white_bold_blue">作业上传:</td>
<td width="294" class="white_bold_blue">目前只能上传<%=filesext%>类型的文件</td>
<td width="170" class="white_bold_blue">备注:</td>
</tr>
<tr>
<td>上传文件:</td>
<td colspan="2">
<input type="hidden" name="filepath" value="Upload/<%response.write session("our_teacher") & "/" & session("student_class") & "/" & work_name & "/" %>">
<input name="file" type="file" class="input_file_01">
</td>
</tr>
<tr>
<td colspan="3" class="center"><b><FONT SIZE="3" COLOR="red"><%=success%></FONT></b><input type="submit" name="Submit2" value="提交">
<input type="reset" name="Submit3" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>