📄 savetofile.asp
字号:
<!--#include FILE="clsUp.asp"-->
<!--#include file="conn.asp"-->
<%
Server.ScriptTimeout=600
if session("username")="" then
response.write "<SCRIPT language=JavaScript>alert('非法进入,或者登录已超时,请重新登录。');this.location.href='vbscript:history.back()';</SCRIPT>"
response.end
end if
dim upfile,formPath,ServerPath,FSPath,FileName,newFilename,path,objfso,sql,rs,conn
set upfile=new clsUp ''建立上传对象
upfile.NoAllowExt="asp;exe;htm;html;aspx;cs;vb;js;" '设置上传类型的黑名单
upfile.GetData (102400000) '取得上传数据,限制最大上传10M
%>
<html>
<head>
<title>文件上传</title>
<style type="text/css">
<!--
.p9{ font-size: 9pt; font-family: 宋体 }
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body leftmargin="20" topmargin="20" class="p9">
<%
if upfile.isErr then '如果出错
select case upfile.isErr
case 1
Response.Write "你没有上传数据呀???是不是搞错了??"
case 2
Response.Write "你上传的文件超出我们的限制,最大10M"
end select
else
%>
<%
FSPath=GetFilePath(Server.mappath("upfile.asp"),"\")'取得当前文件在服务器路径
ServerPath=GetFilePath(Request.ServerVariables("HTTP_REFERER"),"/")'取得在网站上的位置
FileName=upfile.file("file").filename'原来的文件名
newfilename=upfile.AutoSave("file",FSPath&"upload\"&FileName) ''保存文件 也可以使用SaveToFile来保存,参数一样,但是不会自动建立新的文件名
%>
<%
if upfile.iserr then
Response.Write upfile.errmessage
else
sql="select * from file"
rs.open sql,conn,1,3
rs.addnew
rs("filename")=newfilename
rs("user")=session("username")
rs("username")=session("name")
rs("zt")=1
rs("date")=date()'=在数据库里插入当前的时间,格式为年,月,日
rs.update
id=rs("id")
session("fileid")=id
set upfile=nothing '删除此对象
response.Redirect("savefileinfo.asp?id="&id)
end if
end if
%>
</body>
</html>
<%
function GetFilePath(FullPath,str)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, str))
Else
GetFilePath = ""
End If
End function
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -