首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

asp+javascript无组件上传解决方案

2012-02-23 
asp+javascript无组件上传asp+javascript无组件上传的方法,建议,源代码最好!![解决办法]二个文件:一个是up

asp+javascript无组件上传
asp+javascript无组件上传的方法,建议,源代码最好!!

[解决办法]
二个文件:一个是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
%>


[解决办法]
如果我的游览器禁止用js或者不是IE内核怎么办?全部JS很麻烦的。
[解决办法]
可以搜以下 "风云无组件上传组件 ",纯JS的!

热点排行