关于enctype="multipart/form-data"

panyongchao 2004-11-10 03:46:45
我在使用网上下载的图片上传代码的时候,发现upload.asp中代码如下
<form name="form1" method="post" action="uploadSuccess.asp" enctype="multipart/form-data">
<input type="file" name="file1" style="width:200" class="tx1" value="">
<input type="submit" name="submit" value="上传" class="bt">
<input type="reset" name="Submit2" value="取消" class="bt"></td>
</form>
我本来是想在这个表单里加一个
输入附件名称:
<input type="text" name="filename" id="filename">
但是发现在uploadSuccess.asp中取不到filename,后来发现是enctype="multipart/form-data"
地原因,可是这个又不能改掉,不然文件不能上传了。我问一下,那我怎么用其他方法把filename传到
uploadSuccess.asp中去呀!!帮帮我呀
...全文
237 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
panyongchao 2004-11-26
  • 打赏
  • 举报
回复
不好意思好久不来了噢
我提圆满解决,谢谢phoubes(Chris.J)
phoubes 2004-11-18
  • 打赏
  • 举报
回复
==========================================================================================

如果表单使用了enctype="multipart/form-data" 就不能再使用Request.From来读取表单值了,表单内的数据都以二进制流提交,所以只能使用Request.BinaryRead来读取上传数据的二进流,那你就得去分析二进流把你所需要的数据分解出来,并转化成文本字符...

推荐使用这个,提供了Form集合的表单数据读取.

http://community.csdn.net/Expert/topic/3304/3304903.xml?temp=.4265406

下载: http://phoubes.51.net/CjAspUploadScriptv2.1.rar

有详细的文档说明和示例,值得学习...

==========================================================================================
baikaishui_0825 2004-11-18
  • 打赏
  • 举报
回复
xx=upload.form("xxx")
这样应该可以的
我这边都可以用的
Camelot 2004-11-18
  • 打赏
  • 举报
回复
uploadSuccess.asp

<%@LANGUAGE="VBSCRIPT"%>
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!--#include file="Connections/wu.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_wu_STRING
Recordset1.Source = "SELECT * FROM dbo.Mdichanxingxi ORDER BY id DESC"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 3
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<style type="text/css">
<!--
a:link {
color: #0000FF;
text-decoration: none;
}
a:visited {
color: #0000FF;
text-decoration: none;
}
body {
margin-top: 0px;
background-color: #FFFFFF;
}
body,td,th {
font-size: 12px;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body>
<%
dim filenames
'filenames=Request("filename")///////////////不能用这种方法
nun=Request("id")
dim upload,file,formName,formPath,iCount,temp,conn,rs,nun,cs
set upload=new upload_5xsoft ''建立上传对象
filenames=upload.Form("filename")'///////////////要这样获取
if filenames="" then
%>
<p align="center"><font size="2" color="#FF0000">请先输入附件名称!</font><br><br>
<a href="upload.asp">返回上一步</a></p>
<%else
formPath="download/"
dim str
for each formName in upload.objFile
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
str = right(file.FileName, 3)
str = lcase(str)
if str <> "jpg" and str <> "bmp" and str <> "gif" and str<>"doc" and str<>"txt" then %>
<br>
<p align="center">
<font color = ff0000>只能上传jpg, bmp, gif格式的图片,或是doc,txt格式的文档</font>
<a href=upload.asp>确定</a>
</p>
<%else
temp=NOW&Time&file.FileName
temp = Replace(temp, CHR(32), "")
temp = Replace(temp, CHR(45), "")
temp = Replace(temp, CHR(58), "")
file.SaveAs Server.mappath(formPath&temp) ''保存文件

set conn=server.CreateObject ("adodb.connection")
conn.Open (MM_wu_STRING)
if nun="" then
if Recordset1.recordcount=0 then
nun=1
else
nun=Recordset1.Fields.Item("id").Value+1
end if
end if
Set cs=server.CreateObject("ADODB.Recordset")
cs.open "insert into Mxiangmufujian (xiangmufujian,xiangmuid,fujianmingcheng) Values ('" & temp & "'," & nun & ",'" & filenames & "')",conn

conn.close
%>
<p align="center"><font color = 666666>上传成功!</font><br>还要上传其它文件请点击继续<br><br><a href=upload.asp>继续</a><br> </p>
<%
end if
end if
set file=nothing
next

sub HtmEnd(Msg)
set upload=nothing
response.write "<br>"&Msg&" [<a href=""javascript:history.back();"">返回</a>]</body></html>"
response.end
end sub
end if
set upload=nothing ''删除此对象
%>
</body>
</html>

<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
panyongchao 2004-11-17
  • 打赏
  • 举报
回复
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>
panyongchao 2004-11-17
  • 打赏
  • 举报
回复
代码是有的!!大家来帮帮忙呀
uploadSuccess.asp

<%@LANGUAGE="VBSCRIPT"%>
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!--#include file="Connections/wu.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_wu_STRING
Recordset1.Source = "SELECT * FROM dbo.Mdichanxingxi ORDER BY id DESC"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 3
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<style type="text/css">
<!--
a:link {
color: #0000FF;
text-decoration: none;
}
a:visited {
color: #0000FF;
text-decoration: none;
}
body {
margin-top: 0px;
background-color: #FFFFFF;
}
body,td,th {
font-size: 12px;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body>
<%
dim filenames
filenames=Request("filename")///////////////就是这里取不到name
nun=Request("id")
if filenames="" then
%>
<p align="center"><font size="2" color="#FF0000">请先输入附件名称!</font><br><br>
<a href="upload.asp">返回上一步</a></p>
<%else
dim upload,file,formName,formPath,iCount,temp,conn,rs,nun,cs
set upload=new upload_5xsoft ''建立上传对象
formPath="download/"
dim str
for each formName in upload.objFile
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
str = right(file.FileName, 3)
str = lcase(str)
if str <> "jpg" and str <> "bmp" and str <> "gif" and str<>"doc" and str<>"txt" then %>
<br>
<p align="center">
<font color = ff0000>只能上传jpg, bmp, gif格式的图片,或是doc,txt格式的文档</font>
<a href=upload.asp>确定</a>
</p>
<%else
temp=NOW&Time&file.FileName
temp = Replace(temp, CHR(32), "")
temp = Replace(temp, CHR(45), "")
temp = Replace(temp, CHR(58), "")
file.SaveAs Server.mappath(formPath&temp) ''保存文件

set conn=server.CreateObject ("adodb.connection")
conn.Open (MM_wu_STRING)
if nun="" then
if Recordset1.recordcount=0 then
nun=1
else
nun=Recordset1.Fields.Item("id").Value+1
end if
end if
Set cs=server.CreateObject("ADODB.Recordset")
cs.open "insert into Mxiangmufujian (xiangmufujian,xiangmuid,fujianmingcheng) Values ('" & temp & "'," & nun & ",'" & filenames & "')",conn

conn.close
%>
<p align="center"><font color = 666666>上传成功!</font><br>还要上传其它文件请点击继续<br><br><a href=upload.asp>继续</a><br> </p>
<%
end if
end if
set file=nothing
next

set upload=nothing ''删除此对象


sub HtmEnd(Msg)
set upload=nothing
response.write "<br>"&Msg&" [<a href=""javascript:history.back();"">返回</a>]</body></html>"
response.end
end sub
end if
%>
</body>
</html>

<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
Camelot 2004-11-16
  • 打赏
  • 举报
回复
把你的uploadSuccess.asp代码贴出来看看,不贴出来大家都在瞎模



┏━━━.:可爱的分割线:.━━━━━━━━━━━━━━━━━
┃                                
┃在线的RSS订阅系统(Blog、新闻、技术):http://www.gbmad.net/rss/
┃无论你在哪,只要能上网就能订阅查看你喜欢的聚合         
┃                                
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━
xiaol1324 2004-11-16
  • 打赏
  • 举报
回复
set obj=Server.CreateObject("上传类名")

filename=obj.request("filename")

试试
panyongchao 2004-11-14
  • 打赏
  • 举报
回复
不是把没人拉?还没解决那!!!!
panyongchao 2004-11-13
  • 打赏
  • 举报
回复
set file=upload.filename(filename 为上传页面的input的name)
getfilename=file.filename
getfilesize=file.filesize
好像是取得上传文件的名字啊,我要的是自己输入的名字啊
xuhaimei 2004-11-12
  • 打赏
  • 举报
回复
很多空间提供上传类,比如:
sa-fileUp
AspUpload
ljial 2004-11-12
  • 打赏
  • 举报
回复
set file=upload.filename(filename 为上传页面的input的name)
getfilename=file.filename
getfilesize=file.filesize
panyongchao 2004-11-12
  • 打赏
  • 举报
回复
不行的
liuyong320324 2004-11-11
  • 打赏
  • 举报
回复
上面写错了是xx=upload.form("xxx")
liuyong320324 2004-11-11
  • 打赏
  • 举报
回复
你用xx=upload.from("xxx") 试试。
sdts 2004-11-11
  • 打赏
  • 举报
回复
要处理数据 好像有点麻烦 我也在研究这个问题 想好了再来说
panyongchao 2004-11-11
  • 打赏
  • 举报
回复
晕,那也得先取到呀!
xukaisam 2004-11-11
  • 打赏
  • 举报
回复
把传的值放在session里就可以了.
panyongchao 2004-11-11
  • 打赏
  • 举报
回复
我这里没有说明呀?Request.BinaryRead(Request.TotalBytes)加在那个页面地那个地方呀?
什么上传类呀,我不知道呀
-神仙- 2004-11-10
  • 打赏
  • 举报
回复
你是用上传类的吗

看看使用说明
加载更多回复(1)

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧