用下面一段代码上传图片,结果有两个问题:
1.本地上传能成功,但远程错误,提示ADODB.Stream (0x800A0BBA)文件无法被打开. 
2.在本地一个用户每上传一次图片后,图片名会自动加个空格..比如第一次是"张三.JPG",第二次就是" 张三.JPG",第N次就是"N个空格张三.JPG"代码如下:<%
  Function GetFileName(ByVal strFile)
  If strFile<>""Then
   GetFileName=mid(strFile,InStrRev(strFile,"."))
  
  Else
   GetFileName=""
  End If
  End function  strFileName = Request.Form("file1")
  if strFileName<>""then
      Set objStream = Server.CreateObject("ADODB.Stream")
      objStream.Type = 1
      objStream.Open
      objStream.LoadFromFile strFileName
      Path="UserPhoto/"+request("UserID")+GetFileName(strFileName)
      objStream.SaveToFile Server.MapPath(Path),2
      objStream.Close
      response.Write("<script>parent.ShowUserPIC('"+Path+"')</script>")
  end if
  %>
  <html  style=" margin-top:0px; margin-bottom:0px; margin-left:0px ; margin-right:0px">
  <body style=" margin-top:0px; margin-bottom:0px; margin-left:0px ; margin-right:0px; width:120px">
  <form name="FORM" action="upload.asp" method="post"  style="width:100px">
    <div align="center">
     <input type="file" name="file1" style="width:130">
     <input type="submit" name="submit" value="上 传">
     </div>
     <input type="hidden" name="UserID" id="UserID" value="<%=request("id")%>">
  </form>
  </body>
  </html>
求高手指教...感激不尽

解决方案 »

  1.   

    参考:
    <input type="button" name="submit" valule="上传" onclick="javascript:window.open('upfile.htm','width=580,height=60,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=no');return false;">
     
    <upfile.htm>
    <html>
    <head>
    <title>图片上传</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    td {  font-size: 9pt}
    a {  color: #000000; text-decoration: none}
    a:hover {  text-decoration: underline}
    .tx {  height: 16px; width: 30px; border-color: black black #000000; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; font-size: 9pt; background-color: #E8F1FF; color: #0000FF}
    .bt {  font-size: 9pt; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; height: 16px; width: 80px; background-color: #eeeeee; cursor: hand}
    .tx1 { height: 20px; width: 30px; font-size: 9pt; border: 1px solid; border-color: black black #000000; color: #000000}
    .style1 {color: #FF0000}
    -->
    </style>
    </head><body bgcolor="#FFFFFF" text="#000000" topmargin="10">
    <form name="form1" method="post" action="upfile.asp" enctype="multipart/form-data" onSubmit="checkImage('file1')">
      <input type="hidden" name="act" value="upload">
      <table width="560" border="1" cellspacing="0" cellpadding="5" align="center" bordercolordark="#6B8FC8" bordercolorlight="#ffffff">
        <tr bgcolor="#CCCCCC">
          <td height="22" align="left" valign="middle" bgcolor="#6B8FC8">&nbsp;图片上传
          </td>
        </tr>
      
        <tr align="center" valign="middle">
          <td height="60" align="left" bgcolor="#E8F1FF" id="upid"> <input type="hidden" name="filepath" value="/bangdepic/">
            文件1:
            <input type="file" name="file1" style="width:400" class="tx1" value="">
            <br>
            <span class="style1"><br>
            (本类上传图片大小为200*150bps) </span> </td>
        </tr>
        <tr align="center" valign="middle" bgcolor="#eeeeee">
          <td bgcolor="#eeeeee" height="24">
            <input type="submit" name="Submit" value="提 交" class="bt">
            <input type="reset" name="Submit2" value="清 除" class="bt">
          </td>
        </tr>
      </table></form>
    </body>
    </html><script language=javascript>
    function checkImage(sId)
    {
      if(( document.all[sId].value.indexOf(".gif") == -1) && (document.all[sId].value.indexOf(".jpg") == -1)) {
        alert("请选择gif或jpg的图象文件");
        event.returnValue = false;
        }
    }
    </script>
    <upfile.asp>
    <!--#include FILE="upload_ckxp.inc"-->
    <html>
    <head>
    <title>图片上传</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <META content="1F43E3B" name=keywords>
    </head>
    <body bgcolor="#E8F1FF">
    <%
    dim upload,file,formName,formPath,iCount,snameset upload=new upload_5xSoft ''建立上传对象response.write upload.Version&""  ''显示上传类的版本if upload.form("filepath")="" then   ''得到上传目录
     HtmEnd "请输入要上传至的目录!"
     set upload=nothing
     response.end
    else
     formPath=upload.form("filepath")
     ''在目录后加(/)
     if right(formPath,1)<>"/" then formPath=formPath&"/"
    end if
    iCount=0for each formName in upload.file ''列出所有上传了的文件set file=upload.file(formName)  ''生成一个文件对象
      ' response.Write(Server.mappath(formPath&file.FileName)  )
    'response.End()
    if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
       file.SaveAs Server.mappath(formPath&file.FileName)   ''保存文件
     
     response.write "<br><center><font size=2 color=red>上传成功,请复制下边剪切板中内容而后粘贴到剪切板内!</font></center><br>"
      dim thename,fsobj,spp,paths '文件更名
      thename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&right(file.filename,4)
     
      spp=file.filename
      file.filename=thename
      file.SaveAs Server.mappath(formPath&file.FileName)
      paths=server.mappath("/")&"\bangdepic\"&spp
      set fsobj=server.CreateObject("scripting.filesystemobject")
       if fsobj.fileExists(""&paths&"") then
        fsobj.deletefile(""&paths&"")
       end if
      set fsobj=nothing
       response.write "<center>
         <input name="text" type=text value=/bangdepic/"&file.filename&" size=26>
         <button onclick=window.clipboardData.setData('text',this.previousSibling.value)>复制</button><br><br><a href='javascript:window.close()'><font color=red size=2>关闭窗口</font></a></center>"
         iCount=iCount+1
     end if
      set file=nothing
    nextset upload=nothing  ''删除此对象
    response.write "<font color=red size=2>"
    'Htmend iCount&" 个文件上传成功!</font>"sub HtmEnd(Msg)
     set upload=nothing
     response.write "<br>"&Msg&" [<a href='javascript:window.close()'><font color=red size=2>关闭窗口</font></a>]</body></html>"
     response.end
    end sub
    Function GetPP
     dim s
     s=Request.ServerVariables("path_translated")
     GetPP=left(s,instrrev(s,"\",len(s)))
    End function
    %>
    </body>
    </html>