asp上传文件到服务器的代码怎么写?

 我来答
wasdwasd0302
推荐于2019-10-12 · 超过25用户采纳过TA的回答
知道答主
回答量:96
采纳率:100%
帮助的人:64.3万
展开全部
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
'On Error Resume Next
Response.Expires=0
if Request.TotalBytes then
set a=createobject("adodb.stream")
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=clng(instrb(b,c))
e=instrb(d+1,b,c)
set f=createobject("adodb.stream")
f.type=1
f.open
a.Position=d+1
a.copyto f,e-d-3
f.Position=0
f.type=2
f.CharSet="GB2312"
g=f.readtext
f.Close
h=mid(g,instrRev(g,"\")+1,e)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
if j <1 then
set f =nothing
set a =nothing
response.write "未选择要上传的文件<a href='?'>重新上传</a>"
response.end
end if
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j

h = Mid(h, InStrRev(h, "filename=""") + 10) '这是我帮你添加的,文件名的获取没有正确
f.SaveToFile server.mappath("/EXCEL/"& h),2
f.Close
set f=Nothing
a.Close
set a=Nothing
'response.write "<a href="&Server.URlEncode(h)&">"&h&"</a>"
end if
If Err.number<> 0 Then
response.Write err.number
response.Write err.Description
Response.End
End If
%>
<script language="javascript">
function checkupload() {
if (document.upload_form.fe.value == "") {
alert("未选择要上传的文件");
return false;
}
}
</script>
<form name="upload_form" enctype="multipart/form-data" method="post" onsubmit="return(checkupload())">
<input type="file" name="fe"/>
<input type="submit" value="上传" name="B1"/>
</form>
</body>
</html>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式