无组件上传的诡异问题 抛100分!!

comflyer0590 2005-04-11 08:16:53
上传页面:
<form enctype="multipart/form-data" method="post" action="UploadImage3_upload.asp?NewsID=82" name="form1">
<tr><td width=100% ><input type='file' name='file1' size=50></td></tr>
<tr><td width=100% ><input type='file' name='file2' size=50></td></tr>
<tr>
<td width="100%" align=center><input type=submit value=开始上传图片></td>
</tr>
</table>
</form>
。。。。。。。


处理页面:
<%@ LANGUAGE="VBSCRIPT" %>
<!--#include FILE="upload_5xsoft.inc"-->
<%
NewsID=Request.QueryString("NewsID")
Savepath=server.MapPath("../images/news/")
iCount=1

dim upload,file,formName,formPath,iCount
set upload=new upload_5xSoft ''建立上传对象
%>

<table border="0" width="450" align=center>
<tr>
<td width="100%"><b>上传新闻图片:</b></td>
</tr>
<tr>
<td width="100%">
<hr size="1">
</td>
</tr>
<tr>
<td width="100%"><STRONG>上传结果:</STRONG></td>
</tr>
<tr>
<td width="100%">   </td>
</tr>
<%
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
file.SaveAs SavePath & "\" & NewsID & "-" & cstr(iCount)&"."& getFileExtName(file.fileName) ''保存文件
Response.Write "<tr><td>已经保存" & NewsID & "-" & cstr(iCount)&"."& getFileExtName(file.FileName) & "</td></tr>"
else
Response.Write "文件大小为0,文件没保存!"
end if
set file=nothing
iCount=iCount+1
next
set upload=nothing ''删除此对象
%


。。。。。

<%
'获得文件的后缀名
function getFileExtName(fileName)
dim pos
pos=instrrev(filename,".")
if pos>0 then
getFileExtName=mid(fileName,pos+1)
else
getFileExtName=""
end if
end function
%>


问题:执行时只能上传成功上传页面中的第一个图片,第二个图片始终上传不成功,高手们看看怎么回事??!!
...全文
232 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
提交按钮要赋值??呵呵,没碰上过,不写的,不过这么一说我明白了为什么源码里是要<10了,原来是submit,很有道理的回复,看来不求甚解是我的问题,我一直以为是数据流的问题,看来我想错了

我还不知道前20多个字节是干什么用的,这个问题都挺困惑的
underone 2005-04-13
  • 打赏
  • 举报
回复
如果只能得到一个生成文件,有可能你接收过来的数值有问题的,另一种是你的循环有问题
comflyer0590 2005-04-13
  • 打赏
  • 举报
回复
顶!! zy51(Final)来解释一下啊
zy51 2005-04-13
  • 打赏
  • 举报
回复
comflyer0590 (cz) 必须向你更正一下.

你的错误在于没有给submit按钮赋值.更改<input type="submit" name="任意值" value="上传">
就能正确执行了.如果按你的那种方法写.当有2个文件的时候第二个不能上传.当有三个的时候,那第三个不能上传.很自然的.如果你是单个文件上传.按你的写法也一定是错的.必须给提交按钮赋值.

回答你的问题有些草率了.今天才发现.不好意思.
comflyer0590 2005-04-13
  • 打赏
  • 举报
回复
还真行啊 只是这是为事么啊?? 我非常想知道啊, zy51(Final) 这分肯定是给你啦!!!
zy51 2005-04-13
  • 打赏
  • 举报
回复
都说让你参考参考动网的批量上传功能了.

问题在你的上传页面. 插入<input type=hidden name=icount>问题解决.已测试100%成功.

至于为什么,就不用说了.有了这段就再清楚不过了.
comflyer0590 2005-04-12
  • 打赏
  • 举报
回复
顶一个!!!
comflyer0590 2005-04-12
  • 打赏
  • 举报
回复
顶!!
comflyer0590 2005-04-12
  • 打赏
  • 举报
回复
liuxiaoyi666(兔子) 兄 其实问题不在文件命名 因为即使我把上传的处理代码去掉
只保留 response.write icount 运行结果还是1 而不是1,2 问题是出在这里啦 它为何只识别出一个file呢???
  • 打赏
  • 举报
回复
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!--#include FILE="upload_5xsoft.inc"-->
<!--#include FILE="picwl.inc"-->
<% dim id,name,foldername1,foldername2
id=session("id")
if id=0 then
response.redirect("manageindex.htm")
end if
%>

<%
dim upload,file,formName,formPath,iCount,length,pp,height,datey,datem,dated,dateh,datemin,random1,filename,fso
set upload=new upload_5xsoft ''建立上传对象
set fso=server.createobject("scripting.filesystemobject")
dim conn,rs
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "liu","",""
name=session("name")

'formPath=id&"\"
formPath=name&"\"&"photos"&"\"

iCount=0
for each formName in upload.objForm ''列出所有form数据
'response.write formName&"="&upload.form(formName)&"<br>"
next

'response.write "<br>"
for each formName in upload.objFile ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
datey=year(now())
datem=month(now())
dated=day(now())
random1=cint(rnd()*1000)
filename=session("name")
'filename=filename&"_"&datey&datem&dated&random1&"."&file.FileType
filename=filename&"_"&datey&datem&dated&random1&".jpg"

file.SaveAs Server.mappath(formPath&filename) ''保存文件
'response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&formPath&File.FileName&" 成功!<br>"
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "pic",conn,1,3
set pp=new possible
length=pp.readX(Server.mappath(formPath&filename))
height=pp.readY(Server.mappath(formPath&filename))


rs.addnew
rs("picname")=filename
rs("id")=cint(id)
rs("filesize")=cLng(file.filesize)
rs("width")=cLng(length)
rs("height")=cLng(height)
rs.update
iCount=iCount+1
end if
rs.close
set rs=nothing
set file=nothing
next
set upload=nothing ''删除此对象
'Htmend iCount&" 个文件上传结束!"
response.redirect("picdisplay1.asp")
sub HtmEnd(Msg)
set upload=nothing
'response.write "<br>"&Msg&" [<a href=""javascript:history.back();"">返回</a>]</body></html>"
'response.end
end sub
%>
zhangjinzhicn 2005-04-12
  • 打赏
  • 举报
回复
UP
comflyer0590 2005-04-12
  • 打赏
  • 举报
回复
没有啊
当我上传页面两个file都选择图片时 结果 只有第一个上传成功, icount显示的值为1
当上传页面只选择第一个file 第二个file空着时 第一个file上传成功, icount显示的值为1
当上传页面只选择第二个file 第一个file空着时 显示 “文件大小为0,文件没保存!” icount显示的值为1


问题就出在第二个file上 到底是怎么回事啊 ???
underone 2005-04-12
  • 打赏
  • 举报
回复
你传过来的值是不是只有1个啊
underone 2005-04-12
  • 打赏
  • 举报
回复
如果只有第一个成功,其他的都不成功,可能是你的循环有问题
poonzsp 2005-04-12
  • 打赏
  • 举报
回复
顶~下`~
comflyer0590 2005-04-12
  • 打赏
  • 举报
回复
顶一个
comflyer0590 2005-04-12
  • 打赏
  • 举报
回复
madpolice() 我按你的做了, 发现运行时只出现1 而不是2, 这是怎么回事呢?
Tomato77 2005-04-12
  • 打赏
  • 举报
回复
研究一下
  • 打赏
  • 举报
回复
NewsID=Request.QueryString("NewsID")把这个去了

newid你随便写出几个来

把问号后的去掉

试试
comflyer0590 2005-04-12
  • 打赏
  • 举报
回复
顶啊 还没解决啊 各位帮忙啊 分不够再加!!
加载更多回复(8)

28,390

社区成员

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

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