⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upload.asp

📁 fdafaf af
💻 ASP
字号:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%const need_purview=1%>
<!--#include file="localhost.asp"-->
<!--#include FILE="purview.asp"-->
<!--#include FILE="upfile_class.asp"-->
<!--#include FILE="show_error.asp"-->
<!--#include FILE="conn.asp"-->

<%
'文件属性:例如上传文件为c:\myfile\doc.txt
'FileName    文件名       字符串    "doc.txt"
'FileSize    文件大小     数值       1210
'FileType    文件类型     字符串    "text/plain"
'FileExt     文件扩展名   字符串    "txt"
'FilePath    文件原路径   字符串    "c:\myfile"
'使用时注意事项:
'由于Scripting.Dictionary区分大小写,所以在网页及ASP页的项目名都要相同的大小
'写,如果人习惯用大写或小写,为了防止出错的话,可以把
'sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
'改为
'(小写者)sFormName = LCase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'(大写者)sFormName = UCase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
Dim filesext
call opendb()
set rs=conn.execute("select * from eric_config")
filesext=rs("upload_extend")
call closedb()
'filesext="gif,jpg,jpeg,bmp,png,dwg" '允许的上传文件类型
work_name=trim(request.querystring("work_name"))
'response.write work_name
'过滤字符
If Request.QueryString("action")="Upload" Then
	Server.ScriptTimeOut=999999'要是你的论坛支持上传的文件比较大,就必须设置。

	dim upfile,FileName,oFile
	set upfile=new upfile_class ''建立上传对象
	upfile.GetData (1024000)   '取得上传数据,限制最大上传1M
	formPath=upfile.form("filepath")'取得上传路径

	if upfile.err > 0 then  '如果出错
		select case upfile.err
		case 1
		call error("请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]")'没有数据
		case 2
		call error("上传文件单个不能超过1M [ <a href=# onclick=history.go(-1)>重新上传</a> ]")
		end select
		call Iserror()
		response.end
	else

		'for each formName in upfile.file '列出所有上传了的文件
		set oFile=upfile.file("file")'生成一个文件对象
		'FileName=upfile.form("file")'取得文本域的值'
		
		'判断文件类型
		fileExt=lcase(oFile.FileExt)
		if lcase(fileEXT)="asp" or lcase(fileEXT)="asa" or lcase(fileEXT)="aspx" or 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
		file_name=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum'时间加5位随机数
		'work_name为传递过来的该次作业的名称
		file_name=session("student_num_name") & "_" & work_name & "_" & session("student_class") & "_" & file_name
		FileName=file_name&"."&fileExt
		oFile.SaveToFile Server.mappath(formPath&FileName)   ''保存文件
%>
<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>
<table width="600" border="0" align="center" cellpadding="4" cellspacing="1" id="table_01">
  <tr>
    <td class="white_bold_blue">本地文件:</td>
    <td class="white_bold_blue">文件大小:</td>
    <td class="white_bold_blue">文件名:</td>
  </tr>
  <tr>
    <td><%=oFile.FilePath&oFile.FileName%></td>
    <td><%=formatnumber(oFile.filesize/1024,1,-1)):rem 设置输出的数字格式%>KB</td>
    <td><%=FileName%></td>
</tr>  
<%set oFile=nothing
	'next
end if
set upfile=nothing  '删除此对象
'插入数据库操作
call opendb()
upload_path=formPath&FileName
'response.write upload_path
'response.end
num=left(session("student_num_name"),2)
conn.execute("insert into upload_info (upload_username,upload_path,upload_homework_name,class_e,teacher,num) values ('" & session("student") & "','" & upload_path & "','" & work_name & "','" & session("student_class") & "','" & session("our_teacher") & "','" & num & "')")


'判断文件类型是否合格
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
%>
<tr>
    <td colspan="3" align="center" class="red_12pt_font">恭喜一个作业文件上传成功!</td>
</tr>
<tr>
<td colspan="3" align="center"><input name="contiune" type="button" id="contiune" value="继续上传该次作业的其它文件" onClick="history.go(-1)">
&nbsp;      
<input name="manage_index" type="button" id="manage_index" value="返回管理首页" onclick="window.location.href='explain.asp'">
</td>
</tr>
</table>
</body>
</html>
<%
response.end
end if
%>

<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&work_name=<%=work_name%>" method="post" enctype="multipart/form-data" name="form">
  <table width="600" border="0" align="center" cellpadding="4" cellspacing="1" id="table_01">
    <tr>
      <td width="151" class="white_bold_blue">[<%=work_name%>]作业上传:</td>
      <td width="430" class="white_bold_blue">目前只能上传<%=filesext%>类型的文件 </td>
    </tr>
    <tr>
      <td>上传文件:</td>
      <td>
	  <input type="hidden" name="filepath" value="Upload/<%response.write session("our_teacher") & "/" & session("student_class") & "/" & work_name & "/" %>" readonly>
	  <input name="file" type="file" class="input_file_01">
	  </td>
    </tr>
    <tr>
      <td colspan="2" class="center"><input type="submit" name="Submit2" value="提交">
&nbsp;      <input type="reset" name="Submit3" value="重置"></td>
    </tr>
  </table>
</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -