求asp无组件上传 源码

小鸟一个,网上找了好多没搞明白怎么用需要简单安全的代码希望能附带详细使用介绍!追分!... 小鸟一个,网上找了好多没搞明白怎么用 需要简单安全的代码

希望能附带详细使用介绍! 追分!
展开
 我来答
百度网友788bc723b
2009-12-15 · TA获得超过272个赞
知道小有建树答主
回答量:366
采纳率:0%
帮助的人:264万
展开全部
<td width="80%" bgcolor="#C0C0C0"><input name="picurl" type="text" id="picurl" size="40" maxlength="200" class=box1 >
<a href="javascript:;" onClick="javascript:window.open('FileUploads.asp?to=Previewimg','','width=400,height=100,left=300,top=200')" style="font-size:10pt;color:red;">上传图片最大730宽限jpg格式</a></td>

//fileuploads.asp
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkcom(){
if (document.form1.pic.value==""){
alert("一定要有文件才可以!");
return false;
}
return true;
}
//-->
</SCRIPT>
<title>图 片 上 传</title>
</head>

<body leftmargin="0" topmargin="0">
<%
If Request.QueryString("action") = "up" Then
'on error resume next
dim upload,file,formName,formPath,iCount,pic
set upload=new upload_5xsoft ''建立上传对象
' Response.End
set file=upload.file("pic")
if file.FileSize>0 then
pic = file.FileName
sFileSave = lcase(Mid(pic, InStrRev(pic,".")))
if sFileSave <> ".jpg" and sFileSave <> ".gif" and sFileSave <> ".bmp" then
strMsg="<script>alert('只接受jpg,gif,bmp的图形文件!');history.back();</script>"
Response.write strMsg
Response.end
end If
sFileSave=GetRndFileName&sFileSave
file.SaveAs Server.MapPath("../uploadpic")&"/"&sFileSave
pic=sFileSave
end if
set file = nothing
set upload = nothing

%>
<script>
//opener.form1.FileName.value = "<%= File_Name%>"
//opener.form1.Width.value = "<%= imagewidth%>"
//opener.form1.Height.value = "<%= imageheight%>"
opener.document.all.form.picurl.value = "<%=pic%>"
//alert("成功!");
setTimeout("window.close()",1000);
</script>
<%
response.write "<img src='../uploadpic/"&pic&"' border=0>"
Response.End
End If
%>
<div align="center">
<center>
<form enctype="multipart/form-data" name="form1" method="post" action="?to=<%=Request.QueryString("to")%>&action=up" onSubmit="return checkcom();">
<table border="0" width="100%" height="70">
<tr>
<td width="228" height="20">
<p align="center"><font color="red" style=font-size:10pt;>图 片 上 传</font></td>
</tr>

<tr>

<td width="228" height="23">
<p align="center"><INPUT id=pic name="pic" type=file></td>
</tr>
<center>
<tr>
<td width="228" height="14">
<p align="center">
<input type="submit" value="上传" name="submit">  <input type="reset" value="关闭" name="B1" onClick="vbscript:window.close"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<%
Function GetRndFileName()
Dim tmpstr
randomize
tmpstr=Int(1000*rnd)
tmpstr=""&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&tmpstr
GetRndFileName=tmpstr
End Function
%>

//upload_5xsoft.inc
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim Data_5xsoft

Class upload_5xsoft

dim objForm,objFile,Version

Public function Form(strForm)
strForm=lcase(strForm)
if not objForm.exists(strForm) then
Form=""
else
Form=objForm(strForm)
end if
end function

Public function File(strFile)
strFile=lcase(strFile)
if not objFile.exists(strFile) then
set File=new FileInfo
else
set File=objFile(strFile)
end if
end function

Private Sub Class_Initialize
dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
Version="化境HTTP上传程序 Version 2.0"
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set Data_5xsoft = Server.CreateObject("adodb.stream")
Data_5xsoft.Type = 1
Data_5xsoft.Mode =3
Data_5xsoft.Open
Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes)
Data_5xsoft.Position=0
RequestData =Data_5xsoft.Read

iFormStart = 1
iFormEnd = LenB(RequestData)
vbCrlf = chrB(13) & chrB(10)
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
iStart = LenB (sStart)
iFormStart=iFormStart+iStart+1
while (iFormStart + 10) < iFormEnd
iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
tStream.Type = 1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iFormStart
Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
tStream.Close
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestData,sStart)
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set theFile=new FileInfo
'取得文件名
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
'取得文件类型
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart =iInfoEnd
theFile.FileSize = iFormStart -iInfoEnd -3
theFile.FormName=sFormName
if not objFile.Exists(sFormName) then
objFile.add sFormName,theFile
end if
else
'如果是表单项目
tStream.Type =1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iInfoEnd
Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sFormValue = tStream.ReadText
tStream.Close
if objForm.Exists(sFormName) then
objForm(sFormName)=objForm(sFormName)&", "&sFormValue
else
objForm.Add sFormName,sFormValue
end if
end if
iFormStart=iFormStart+iStart+1
wend
RequestData=""
set tStream =nothing
End Sub

Private Sub Class_Terminate
if Request.TotalBytes>0 then
objForm.RemoveAll
objFile.RemoveAll
set objForm=nothing
set objFile=nothing
Data_5xsoft.Close
set Data_5xsoft =nothing
end if
End Sub

Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
End Class

Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileType,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
End Sub

Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=true
if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
Data_5xsoft.position=FileStart
Data_5xsoft.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
</SCRIPT>

上传到上一个目录的uploadpic里面

参考资料: http://www.csjiazheng.com.cn/index.html长沙家政

StevenWong_BD
2009-12-15 · TA获得超过550个赞
知道小有建树答主
回答量:1587
采纳率:0%
帮助的人:1374万
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式