手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp编程>列表

无组件上传图片之文件采用方案

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>


2,表单页面index.asp。注意包含的上传选择页upload.asp


<form name="form_name" method="POST" action="add.asp">
<textarea cols="100" name="cn_content" rows="18" width="100%"></textarea>
</form>

<iframe border="0" frameBorder="0" noResize scrolling="no" width="100%" src="upload.asp"></iframe>




3,上传选择页upload.asp 注意: enctype="multipart/form-data"


<form name="form" method="post" action="upfile.asp" enctype="multipart/form-data">
<input type="hidden" name="filepath" value="uploadimg">
<input type="hidden" name="act" value="upload">
<input type="file" name="file1" size=40>
<input type="submit" class=button name="Submit" value="上传图片" onclick="parent.document.forms[0].Submit.disabled=true">类型:gif,jpg,限制:100K
</form>




4,最后一 个文件 upfile.asp 主要作用:生成图片名,并将图片上传,同样也要将UBB标签写入index.asp中的textarea中。
(拷贝以下文本框的所有代码)

<!--#include file="upload.inc"-->

<html>
<head>
<title>文件上传</title>
</head>
<body>

<script>
parent.document.forms[0].Submit.disabled=false;
</script>
<%
dim upload,file,formName,formPath,iCount,filename,fileExt
set upload=new upload_5xSoft ''建立上传对象

formPath=upload.form("filepath")
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"

response.write "<body>"

iCount=0
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.filesize<100 then
response.write "请选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
response.end
end if

if file.filesize>100*1000 then
response.write "文件大小超过了限制100K [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
response.end
end if

fileExt=lcase(right(file.filename,4))
uploadsuc=false
Forum_upload="gif,jpg,png"
Forumupload=split(Forum_upload,",")
for i=0 to ubound(Forumupload)
if fileEXT="."&trim(Forumupload(i)) then
uploadsuc=true
exit for
else
uploadsuc=false
end if
next
if uploadsuc=false then
response.write "文件格式不正确 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
response.end
end if

randomize
ranNum=int(90000*rnd) 10000
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&fileExt

if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(FileName) ''保存文件
for i=0 to ubound(Forumupload)
if fileEXT="."&trim(Forumupload(i)) then
response.write "<script>parent.form_name.cn_content.value ='[img]"&FileName&"[/img]'</script>"
exit for
end if
next
iCount=iCount 1
end if
set file=nothing
next
set upload=nothing ''删除此对象

Htmend iCount&" 个文件上传结束!"

sub HtmEnd(Msg)
set upload=nothing

response.write "上传成功 [ <a href=# onclick=history.go(-1)>继续上传</a>]"
response.end
end sub

%>
</body>
</html>

当然,保持图片的文件夹uploadimg不能少

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!