| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2497 人关注过本帖
标题:在一个表单里插入一个表单,上传图片不能获取到地址怎么回事?
只看楼主 加入收藏
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
结帖率:46.67%
收藏
已结贴  问题点数:12 回复次数:7 
在一个表单里插入一个表单,上传图片不能获取到地址怎么回事?
在一个表单里插入一个表单,一个不能获取到地址怎么回事?
<form name="myform" method="post" action="saveaddpro.asp?action=add">
*****
<form name="myform1" method="post" action="savepro.asp?action=add">
     <input name="oPic" type="hidden" id="oPic" size="68"><input name="S_oPic" type="text" id="S_oPic" size="30"><input type="button" name="button4" value="上传图片" onClick="window.open('Load.asp?oUpLoadType=oAspJpeg&FormName=myForm1&FormInput=oPic','','status=no,scrollbars=no,top=20,left=110,width=420,height=165')">

</form>
</form>
代码是这样。上传完图片,图片的地址不能保存在上传文本框中,图片是上传成功了,有什么办法可以做到呢。将上传的地址显示在S_oPic文本框中。
搜索更多相关主题的帖子: 上传图片 
2011-04-19 20:56
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:4 
第一,用一个表单就行了,用两个套在一起做什么?
第二,关于返回上传文件地址,假设你上传的页面返回的图片地址是FileURL,在上传页面加下面代码
<script language="JavaScript" type="text/javascript">
parent.document.myform1.S_oPic.value='<%=FileURL%>';
</script>

----我怎能在别人的苦难面前转过脸去----
2011-04-20 08:48
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
收藏
得分:0 
UPLOAD.ASP代码
程序代码:
<!--#include file="UpLoad_Class.asp"-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.>
<html xmlns="http://www. xml:lang="zh-cn" lang="zh-cn">
<head>
<title>上传文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<style type="text/css">
td,div,input,select,textarea,body {font-size:12px;}
body,form{margin:0px;padding:0;}
</style>
</head>
<body>
<%
'=====================================================================
' 文件名称:UpLoad.Asp
'=====================================================================
'------------------------------------------------------
Dim FormName,FormInput,oUpLoadType,oAction,oFileExe,ooFileSize,oFileSize,IsPicS,PicSp
'------------------------------------------------------
Response.Buffer = True
Response.ExpiresAbsolute = Now()-1
Response.Expires = 0
Response.CacheControl = "no-cache"
Response.Charset = "GB2312"
'------------------------------------------------------
FormName = Trim(Request("FormName"))
FormInput = Trim(Request("FormInput"))
oUpLoadType = Trim(Request("oUpLoadType"))
'------------------------------------------------------
Select Case oUpLoadType
    '------------------------------------------- oAspJpeg
    Case "oAspJpeg"
        oFileExe = "jpg|gif|swf|png"
        sFileSize = 540
    '-------------------------------------------
    Case Else
        oFileExe = "jpg|gif|swf|png"
        sFileSize = 888
End Select
oFileSize = 1024*sFileSize
'------------------------------------------------------
oAction = Trim(Request("oAction"))
Select Case oAction
    Case "UpLoadShow"
        Call UpLoadShow()
    Case "oUpLoad"
        Call oUpLoad()
    Case Else
        Call UpLoadShow()
End Select
'------------------------------------------------------
Sub UpLoadShow()
%>
<div style="text-align:center; margin:5px; padding:5px;">
<form name="upload" method="post" action="UpLoad.asp?oAction=oUpLoad&FormName=<%=FormName%>&FormInput=<%=FormInput%>" enctype="multipart/form-data">
  <table width="400" border="0" cellspacing="1" cellpadding="0" align="center" bgcolor="#35867B">
    <tr>
      <td width="400" height="22" align="left" valign="middle" bgcolor="#35867B">&nbsp;<strong>图片上传</strong>
      </td>
    </tr>
    <tr align="center" valign="middle">
      <td align="left" id="upid" height="80" width="400" bgcolor="#FFFFFF"> 选择文件:
        <input type="hidden" name="oUpLoadType" value="<%=oUpLoadType%>" /><input type="file" name="myUpLoad" />
      </td>
    </tr>
    <tr><td bgcolor="#FFFFFF">文件上传大小:<font color="blue"><%=BytesToString(oFileSize)%></font> 文件上传类型:<font color="red"><%=oFileExe%></font></td></tr>
    <tr align="center" valign="middle">
      <td height="24" width="400">
        <input type="submit" name="Submit" value="开始上传" class="button">
      </td>
    </tr>
  </table>
</form>

</div>
<%
End Sub
'------------------------------------------------------
Sub oUpLoad()
    Dim Upload,path,tempCls,fName,UpLoadFile
    '===============================================================================
    Set Upload = New AnUpLoad            '创建类实例
    Upload.SingleSize = oFileSize        '设置单个文件最大上传限制,按字节计;默认为不限制
    Upload.MaxSize = 1024*1024*1024        '设置最大上传限制,按字节计;默认为不限制
    Upload.Exe = oFileExe                '设置合法扩展名,以|分割,忽略大小写
    Upload.Charset = "gb2312"            '设置文本编码,默认为gb2312
    Upload.openProcesser = False        '禁止进度条功能,如果启用,需配合客户端程序
    Upload.GetData()                    '获取并保存数据,必须调用本方法
    '===============================================================================
    If Upload.ErrorID>0 Then                '判断错误号,如果myupload.Err<=0表示正常
        Response.Write Upload.Description    '如果出现错误,获取错误描述
    Else
        If Upload.files(-1).count > 0 Then    '这里判断你是否选择了文件
            oUpLoadType = Upload.Forms("oUpLoadType")
            Select Case oUpLoadType
                Case "oAspJpeg"
                    UpLoadFile = "../UpLoadFiles/"
                Case Else
                    UpLoadFile = "../UpLoadFiles/"
            End Select
            path = Server.MapPath(UpLoadFile)         '文件保存路径
            Set tempCls = Upload.files("myUpLoad")
            tempCls.SaveToFile path,0
            fName = tempCls.FileName
            Set tempCls = Nothing
            UpLoadFileName = UpLoadFile&fName
           
            If IsObjInstalled("Persits.Jpeg") Then
                S_UpLoadFileName = UpLoadFile&fName
                oS_Pic = StartJpeg(UpLoadFileName,S_UpLoadFileName)
                Call S_UpLoadOpener(FormName,"S_"&FormInput,oS_Pic)
                Call UpLoadOpener(FormName,FormInput,UpLoadFileName,"上传成功!")
            Else
                Call UpLoadOpener(FormName,FormInput,UpLoadFileName,"上传成功!")
            End If
        Else
            Call GoUpLoad("您没有上传任何文件!")
        End If
    End If
    Set Upload = Nothing
End Sub
'------------------------------------------------------
Sub UpLoadOpener(FName,FInput,FValue,OutStr)
    Echo("<script language=""javascript"" type=""text/javascript"" charset=""gb2312"">")
    Echo("window.opener.document."&FName&"."&FInput&".value='"&FValue&"';")
    Echo("alert('"&OutStr&"');")
    Echo("window.opener =null;")
    Echo("window.close();")
    Echo("</script>")
End Sub
'------------------------------------------------------
Sub S_UpLoadOpener(FName,FInput,FValue)
    Echo("<script language=""javascript"" type=""text/javascript"" charset=""gb2312"">")
    Echo("window.opener.document."&FName&"."&FInput&".value='"&FValue&"';")
    Echo("</script>")
End Sub
'------------------------------------------------------
Sub GoUpLoad(OutStr)
    Echo("<script language=""javascript"" type=""text/javascript"" charset=""gb2312"">")
    Echo("alert('"&OutStr&"');")
    Echo("history.go(-1);")
    Echo("</script>")
End Sub
'------------------------------------------------------
Sub Echo(str)
    Response.Write(str) & vbcrlf
End Sub
'------------------------------------------------------
Function BytesToString(ByVal iSize)
    Dim sRet,KB,MB,S
    KB = 1024 : MB = KB * KB
    If Not IsNumeric(iSize) Then
        BytesToString = "未知"
        Exit Function
    End If
    If iSize < KB Then
        sRet = iSize & " Bytes"
    Else
        S = iSize / KB
        If S < 10 Then
            sRet = FormatNumber(iSize / KB, 2, -1) & " KB"
        ElseIf S < 100 Then
            sRet = FormatNumber(iSize / KB, 1, -1) & " KB"
        ElseIf S < 1000 Then
            sRet = FormatNumber(iSize / KB, 0, -1) & " KB"
        ElseIf S < 10000 Then
            sRet = FormatNumber(iSize / MB, 2, -1) & " MB"
        ElseIf S < 100000 Then
            sRet = FormatNumber(iSize / MB, 1, -1) & " MB"
        ElseIf S < 1000000 Then
            sRet = FormatNumber(iSize / MB, 0, -1) & " MB"
        ElseIf S < 10000000 Then
            sRet = FormatNumber(iSize / MB / KB, 2, -1) & " GB"
        Else
            sRet = FormatNumber(iSize / MB / KB, 1, -1) & " GB"
        End If
    End If
    BytesToString = sRet
End Function
Function IsObjInstalled(strClassString)
    On Error Resume Next
    IsObjInstalled = False
    Err = 0
    Dim xTestObj
    Set xTestObj = Server.CreateObject(strClassString)
    If 0 = Err Then IsObjInstalled = True
    Set xTestObj = Nothing
    Err = 0
End Function
Function StartJpeg(CodePic,IsCodePic)
    '================aspJpeg 开始====================
    If (CodePic = "" Or IsNull(CodePic)) Then
        Exit Function
    End If
    If JpegType <> 0 Then
       
        Set BG = Server.CreateObject("Persits.Jpeg")
        BG.Open Server.MapPath(CodePic)
        BG_W = BG.Width
        BG_H = BG.Height
       
        If JpegType = 1 Then
            BG.Canvas.Font.Color = "&H" & JpegColor
            BG.Canvas.Font.ShadowColor = &HFFFFFF
            BG.Canvas.Font.Family = JpegFont
            BG.Canvas.Font.Size = JpegSize
            BG.Canvas.Font.Bold = False
            BG.Canvas.Font.Quality = 3
            Select Case JpegLocation
                Case 0
                    x = 20 : y = 20
                Case 1
                    x = BG_W - Len(JpegTxt) * 15 : y = 20
                Case 2
                    x = 20 : y = BG_H - 20
                Case 3
                    x = BG_W - Len(JpegTxt) * 15 : y = BG_H - 20*2
                Case 4
                    x = BG_W\2 - Len(JpegTxt) * 15\2 : y = BG_H\2 - 20*2
            End Select
            BG.Canvas.PrintText x, y, JpegTxt
        End If
       
        If JpegType = 2 Then
            Set logo = Server.CreateObject("Persits.Jpeg")
            logo.Open Server.MapPath(JpegPic)
            logo_w = logo.Width
            logo_h = logo.Height
            Select Case JpegLocation
                Case 0
                    x = 20 : y = 20
                Case 1
                    x = BG_W - logo_w - 20 : y = 20
                Case 2
                    x = 20 : y = logo_h - 20
                Case 3
                    x = BG_W - logo_w - 20 : y = BG_H - logo_h - 20
                Case 4
                    x = BG_W\2 - logo_w\2 : y = BG_H\2 - logo_h - 20
            End Select
            BG.DrawImage x, y, logo, 0.8, &HFFFFFF
            Set logo = Nothing
        End If
       
        BG.Quality = 85
       
        BG.Save Server.MapPath(IsCodePic)
        Set BG = Nothing
        StartJpeg = IsCodePic
    End If
    '================aspJpeg 结束====================
End Function
%>
</body>
</html>


宏星电脑医生http://www.
全国淘宝充值旗舰店http://czpt8./
2011-04-20 19:35
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
收藏
得分:0 
程序代码:
<form name="myform" method="post" action="saveaddpro.asp?action=add">

 <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="table_southidc">
          <tr bgcolor="#ECF5FF">
            <td width="15%">所属类别:</td>
            <td colspan="2"> <%
        sql = "select * from BigClass"
        rs.open sql,conn,1,1
        if rs.eof and rs.bof then
            response.write "请先添加栏目。"
        else
        %> <select name="BigClassName" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)" size="1">
                      <option selected value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
                      <%
            dim selclass
            selclass=rs("BigClassName")
            rs.movenext
            do while not rs.eof
            %>
                      <option value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
                      <%
                rs.movenext
            loop
        end if
        rs.close
            %>
                    </select>
                    <select name="SmallClassName">
                      <option value="" selected>不指定小类</option>
                      <%
            sql="select * from SmallClass where BigClassName='" & selclass & "'"
            rs.open sql,conn,1,1
            if not(rs.eof and rs.bof) then
            %>
                      <option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
                      <% rs.movenext
                do while not rs.eof%>
                      <option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
                      <%
                    rs.movenext
                loop
            end if
            rs.close
            %>
                      <%
            ranNum=int(9*rnd)+10
            iddata=month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
            %>
                    </select>
                    </strong><strong><font color="#FF0000">*</font></strong></td>
          </tr>
          <tr bgcolor="#ECF5FF">
                  <td width="15%" height="22">产品编号:</td>
                  <td colspan="2"> <strong>
<input name="Product_Id" type="text" id="Product_Id" value="<%=iddata%>" size="10" maxlength="10" readonly>
<font color="#FF0000">*产品编号不可以相同,如你不能确定会重复,请勿改动它!</font></strong>                 </td>
          </tr>
          <tr bgcolor="#ECF5FF">
            <td>产品名称:            </td>
            <td colspan="2"> <input name="Title" type="text" id="Title2" size="30" >
            <strong><font color="#FF0000">*</font></strong></td>
          </tr>
           <tr bgcolor="#ECF5FF">
            <td>点评:</td>
            <td colspan="2" valign="top"><textarea rows="6" name="Memo" cols="80">对该产品进行简单的介绍</textarea>
            <strong><font color="#FF0000">*</font></strong> </td>
          </tr>
          <tr bgcolor="#ECF5FF">
            <td valign="top">产品说明:
            <strong><font color="#FF0000">*</font></strong> </td>
            <td colspan="2">
                <INPUT type="hidden" name="n_Content">   
              <iframe ID="n_Content" src="htmledit/ewebeditor.asp?id=n_Content&style=standard" frameborder="0" scrolling="no" width="600" HEIGHT="550"></iframe>            </td>
          </tr>
          <tr bgcolor="#ECF5FF">
                  <td>产品图片: </td>
                  <td height="21">
     <input name="S_oPic" type="text" id="S_oPic" size="30"><input type="button" name="button4" value="上传图片" onClick="window.open('UpLoad.asp?oUpLoadType=oAspJpeg&FormName=myForm&FormInput=S_oPic','','status=no,scrollbars=no,top=20,left=110,width=420,height=165')">
</td>         
          </tr>
          <tr bgcolor="#ECF5FF">
                  <td height="22">其他选项:</td>
                  <td colspan="2"><input name="Newproduct" type="checkbox" id="Newproduct" value="yes">
                    <font color="#FF0000">新品</font>
                    <input name="Elite" type="checkbox" id="Elite" value="yes">
                    <font color="#FF0000">推荐</font> </td>
          </tr>
          <tr bgcolor="#ECF5FF">
                  <td height="22">录入时间:</td>
                  <td colspan="2"><input name="UpdateTime" type="text" id="UpdateTime2" value="<%=date()%>" maxlength="50">
                    当前时间为:<%=date()%> 注意不要改变格式。</td>
          </tr>
          <tr bgcolor="#ECF5FF">
            <td height="25"></td>
            <td colspan="2"><input type="submit" name="Submit" value="添 加"><input name="n_content" type="hidden" id="n_content" value="<% = Server.HtmlEncode(rs("Content")) %>"> </td>
          </tr>
        </table>
        
      </form>
UPLOAD.ASP,这个上传完这个页面不能关闭。如果把这个代码删除<form name="myform" method="post" action="saveaddpro.asp?action=add">
将可以上传,是不是两个表单的原因,还不知道要怎么修改。

然后上传完页面没关闭查看静态源文件代码如下
程序代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.">
<html xmlns="http://www." xml:lang="zh-cn" lang="zh-cn">
<head>
<title>上传文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<style type="text/css">
td,div,input,select,textarea,body {font-size:12px;}
body,form{margin:0px;padding:0;}
</style>
</head>
<body>
<script language="javascript" type="text/javascript" charset="gb2312">
window.opener.document..S_.value='../UpLoadFiles/201104201936585270149972.jpg';
</script>
<script language="javascript" type="text/javascript" charset="gb2312">
window.opener.document...value='../UpLoadFiles/201104201936585270149972.jpg';
alert('上传成功!');
window.opener =null;
window.close();
</script>

</body>
</html>




宏星电脑医生http://www.
全国淘宝充值旗舰店http://czpt8./
2011-04-20 19:37
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:4 
enctype="multipart/form-data"
上传文件表单一旦加入了这个属性就意味着不能使用Request来获取表单的其他信息了,因为表单的数据已经从文本变为二进制码数据了
2011-04-21 09:42
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
收藏
得分:0 
如果删除这个 enctype="multipart/form-data"就不能上传了。提示“未设置上传表单enctype属性为multipart/form-data或者未设置method属性为post,上传无效”

宏星电脑医生http://www.
全国淘宝充值旗舰店http://czpt8./
2011-04-21 20:06
gflnn
Rank: 2
等 级:论坛游民
帖 子:8
专家分:26
注 册:2011-4-21
收藏
得分:4 
删除这个 enctype="multipart/form-data"就好像能上传吧

[url=]牛尔推荐[/url] [url=]朵拉朵尚[/url]
2011-04-21 20:37
fjhtf
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-4-29
收藏
得分:0 
以下是引用gflnn在2011-4-21 20:37:27的发言:

删除这个 enctype="multipart/form-data"就好像能上传吧
如果删除这个 enctype="multipart/form-data"就不能上传了。提示“未设置上传表单enctype属性为multipart/form-data或者未设置method属性为post,上传无效”

宏星电脑医生http://www.
全国淘宝充值旗舰店http://czpt8./
2011-04-22 15:07
快速回复:在一个表单里插入一个表单,上传图片不能获取到地址怎么回事?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.089920 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved