asp简单⽂件上传源码
⽂件1.上传界⾯⽂件 upload.htm
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>⽂件上传</title>
</head>
<body>
<form method="POST" action="SaveFile.asp">
⽂件上传:<input type="file" name="file" size="42"> <input type="submit" value="提交" name="bb"> </form>
</body>
</html>
⽂件2.保存上传⽂件 SaveFile.asp
<%
dim file,filename,houzui
file = Request.Form("file")
if file="" then
response.write"<script>alert('请选择要上传的⽂件!');window.location.href='upload.htm';</script>"
else
houzui=mid(file,InStrRev(file, "."))
if houzui=".gif" or houzui=".jpg" or houzui=".bmp" then '允许上传的⽂件类型
filename=year(date) & month(date) & day(date) & Hour(time) & minute(time) & second(time) & houzui
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile file
objStream.SaveToFile Server.MapPath(filename),2
objStream.Close
//============================把⽂件名写⼊数据库,如⽆需要,可删除此段代码!
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("mb.mdb")
set rs=server.CreateObject("dset")
rs.open "select*from img",conn,1,2
rs.addnew
rs("name")=filename
rs.update
set rs=nothing
conn.closeasp查看源码配置ui
set conn=nothing
//========================================
response.write"<script>alert('图⽚上传成功!');window.location.href='upload.htm';</script>"
else
response.write"<script>alert('不允许上传" & houzui & "的格式!');window.location.href='upload.htm';</script>" end if
end if
%>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论