当前位置:编程学习 > asp >>

asp文件上传

答案:

⑴.安装文件上传组件Asp fileup(支持多文件上传,文件类型及大小判断,文件上传后改名等)
⑵.重起IIS以使上传组件生效
⑶.设置上传目录的文件权为Internet用户可以读取、写入和修改
⑷.代码部分
upload_file.htm
<style type="text/css">
<!--
.input {background-color: #FFFFFF; border-bottom: black 1px solid;border-left: black 1px solid; border-right: black 1px solid;border-top: black 1px solid; color: #000000;font-family: Georgia; font-size: 9pt;color: midnightblue;}
a:link {color: #1B629C; text-decoration: none}
a:hover {color: #FF6600; text-decoration: underline}
a:visited {text-decoration: none}
-->
</style>

<center>
<form enctype="multipart/form-data" method="post" action="upload_file.asp" name="Upload">
<input type="hidden" name="CopyrightInfo" value="http://www.chinaasp.com">
请选择文件:<input type="file" name="file1" class="input"><br><br>
请选择文件:<input type="file" name="file2" class="input"><br><br>
</form>
<br><br>
<a href=></center>


upload_file.asp
<%
on error resume next

‘定义获得文件后缀的函数
function getfileextname(filename)
pos=instrrev(filename,".")
if pos>0 then
getfileextname=mid(filename,pos+1)
else
getfileextname=""
end if
end function

‘定义获取文件正名的函数
function getfilename(filename)
lens=len(filename)-len(getfileextname(filename))-1
getfilename=left(filename,lens)
end function

‘创建文件上传组件的对象
set fileup=server.createobject("chinaasp.upload")

‘循环读取用户上传的文件,并保存在服务器上
for each f in fileup.files

‘当用户没有选择文件或文件大小超过10m时返回到选择上传文件的页面
if f.filename="" or f.filesize>10485500 then response.redirect "upload_file.htm"

‘获取保存的路径
path=server.mappath("upload_file.asp")
path=left(path,len(path)-15)

‘保存文件
f.saveas path&getfilename(f.filename)&"."&getfileextname(f.filename)

next

response.redirect "upload_file.htm"
%>

上一个:数据库多表连接查询
下一个:SQL数据库的连接方式

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,