您的位置:程序门 -> web 开发 -> asp



asp+javascript无组件上传


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


asp+javascript无组件上传[已结贴,结贴人:mataofq]
发表于:2007-05-15 17:23:49 楼主
asp+javascript无组件上传的方法,建议,源代码最好!!
发表于:2007-05-18 10:27:291楼 得分:0
asp+javascript无组件上传的方法,建议,源代码最好!!
发表于:2007-05-18 10:27:392楼 得分:0
asp+javascript无组件上传的方法,建议,源代码最好!!
发表于:2007-05-18 10:38:463楼 得分:30
二个文件:一个是upload.asp,用于嵌套到你需的要asp文件,记录加一个参数:pic=你需要填充上传文件路径的控件名,源码如下:
<html>
<head>
<%
dim   pic
pic=request.querystring( "pic ")
%>
<%if   request.querystring( "photourl ") <>   " "   then%>
<script>
if(opener.form1. <%=pic%> .value== " ")
{
opener.form1. <%=pic%> .value+= "file/ <%=request.querystring( "photourl ")%> ";

}
else
{
opener.form1. <%=pic%> .value= "file/ <%=request.querystring( "photourl ")%> ";
}
window.close();
</script>
<%end   if%>
<title> 文件上传 </title>
</head>
<body   background=image/bg.gif>
<table   width= "100% "   border= "0 "   cellspacing= "0 "   cellpadding= "0 ">
    <tr>
        <td   align= "center "> 上传图片 </td>
    </tr>
</table>

<form   action= "upload_check.asp?pic= <%=pic%> "   method= "post "   enctype= "multipart/form-data ">
<table   cellpadding=0   cellspacing=0   border=0   width=100%   align= "center ">
<tr>
<td   width= "70% "   align= "right ">
<input   type=file   name=file1   style= "border:1px   solid   #808000;   width:180;height:22;background-color=#ffffff "   size= "20 "> </td>
<td   width= "30% "   align= "left "> &nbsp;&nbsp; <input   type=submit   value= "上传... "   style= "border:1px   solid   #808000;   background-color=#ebe9ed;width=50;height:19 ">
<td>
</tr>
</table>
</form>
</body>
</html>


另一个是用于上传文件的asp文件:upload_check.asp,源码如下:


<%
dim   pic
pic=request.querystring( "pic ")
function   btos   (bstr)  
if   bstr <> " "   then  
for   i   =   0   to   lenb(bstr)   -   1  
bchr   =   midb(bstr,i+1,1)  
temp   =   temp&chr(ascb(bchr))  
next  
end   if  
btos   =   temp  
end   function  

formsize=request.totalbytes
if   formsize <> 0   and   session( "username ")   =   " "   then

formdata=request.binaryread(formsize)

bncrlf=chrb(13)   &   chrb(10)

divider=leftb(formdata,clng(instrb(formdata,bncrlf))-1)

ender=bncrlf   &   divider   &   chrb(45)   &   chrb(45)

bodyjpg=midb(formdata,instrb(formdata,bncrlf&bncrlf)+lenb(bncrlf&bncrlf),instrb(formdata,ender)-instrb(formdata,bncrlf&bncrlf)-lenb(bncrlf&bncrlf))

if   lenb(bodyjpg) <=20485760   then

typeis=chrb(084)&chrb(121)&chrb(112)&chrb(101)&chrb(058)&chrb(032)

typepath=midb(formdata,instrb(formdata,typeis)+lenb(typeis),instrb(instrb(formdata,typeis)+lenb(typeis),formdata,bncrlf)-instrb(formdata,typeis)-lenb(typeis))

contentype=btos(typepath)


if   contentype= "application/msword "   then
photos= "1 "
filename3= "doc "
elseif   contentype= "application/vnd.ms-excel "   then
photos= "1 "
filename3= "xls "
elseif   contentype= "application/octet-stream "   then
photos= "1 "
filename3= "rar "
elseif   contentype= "application/x-zip-compressed "   then
photos= "1 "
filename3= "zip "

elseif   contentype= "image/bmp "   then
photos= "1 "
filename3= "bmp "

elseif   contentype= "image/gif "   then
photos= "1 "
filename3= "gif "

elseif   contentype= "image/pjpeg "   then
photos= "1 "
filename3= "jpg "
else
photos= "0 "
end   if

if   photos= "1 "     then

dim   namenumber
timename=cstr(now())
for   i=1   to   len(timename)
thisnumber=mid(timename,i,1)
if   thisnumber= "0 "   or   thisnumber= "1 "   or   thisnumber= "2 "   or   thisnumber= "3 "   or   thisnumber= "4 "   or   thisnumber= "5 "   or   thisnumber= "6 "   or   thisnumber= "7 "   or   thisnumber= "8 "   or   thisnumber= "9 "   then
namenumber=namenumber&thisnumber
end   if
next


set   allbody   =   server.createobject( "adodb.stream ")
allbody.type   =   1
allbody.mode   =3
allbody.open

set   photobody   =   server.createobject( "adodb.stream ")
photobody.type   =   1
photobody.mode   =3
photobody.open


allbody.write   formdata
allbody.position   =   instrb(formdata,bncrlf&bncrlf)+lenb(bncrlf&bncrlf)-1
allbody.copyto   photobody,lenb(bodyjpg)

photobody.savetofile   server.mappath( "..\..\upload\ "&namenumber& ". "&filename3),2

allbody.close
set   allbody   =   nothing
photobody.close
set   photobody   =   nothing

response.write   " <script> alert( '文件上传成功 ');window.location.href= 'upload.asp?pic= "&pic& "&photourl= "&namenumber& ". "&filename3& " '; </script> "
else

response.write " <script> alert( '上传文件格式错误 ');window.location.href= 'upload.asp '; </script> "
end   if
else

response.write " <script> alert( '文件大小超出1m限制 ');window.location.href= 'upload.asp '; </script> "

end   if
else

response.write   " <script> alert( '文件上传成功 ');window.location.href= 'upload.asp?photourl= "&namenumber& ". "&filename3& " '; </script> "
end   if
%>

发表于:2007-05-19 11:06:004楼 得分:0
有没有js版本的啊
发表于:2007-05-19 11:06:135楼 得分:0
asp+javascript无组件上传的方法,建议,源代码最好!!
发表于:2007-05-19 14:56:076楼 得分:0
吐血~~~~~~~~~~~~~你不是要asp+js的版本吗?我给你的就是asp+js的版本啊...难道你想全部用js写的啊?没有~~~
发表于:2007-05-19 15:27:367楼 得分:10
如果我的游览器禁止用js或者不是ie内核怎么办?全部js很麻烦的。
发表于:2007-05-19 19:09:138楼 得分:10
可以搜以下 "风云无组件上传组件 ",纯js的!
发表于:2007-05-21 10:40:049楼 得分:0
asp+javascript无组件上传的方法,建议,源代码最好!!
发表于:2007-05-21 10:40:1310楼 得分:0
asp+javascript无组件上传的方法,建议,源代码最好!!
发表于:2007-05-21 10:54:2911楼 得分:0
收收
发表于:2007-05-21 11:47:3412楼 得分:0
asp+javascript无组件上传的方法,建议,源代码最好!!
发表于:2007-05-21 11:47:4013楼 得分:0
asp+javascript无组件上传的方法,建议,源代码最好!!


快速检索

最新资讯
热门点击