标题:求助ASP上传图片写入数据库问题
取消只看楼主
qiage777
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-7
结帖率:0
已结贴  问题点数:20 回复次数:6 
求助ASP上传图片写入数据库问题
一个无组件图片上传程序 上传的图片是以当前时间命名的,然后把图片名字写入数据库,上传写入都没有问题,只是要修改这个上传的图片时,就是要更新这个图片时,最新生成的图片名是可以写进数据库的,但是这新的图片名直接就写在旧的图片名后面,而不是更新旧的图片名,

[附件ID:attach_1名称:1.jpg]
picture2.asp 这是文件名

<html>
<head>
<title>上传图片</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet" type="text/css">
<script language=javascript>

function check()

{
 
  if(myform.file1.value=="")
    {
    alert("请点击浏览按钮,选择您要上传的jpg或gif文件!")
    myform.file1.focus;
    return (false);
    }
    else
    {
    str= myform.file1.value;
    strs=str.toLowerCase();
    lens=strs.length;
    extname=strs.substring(lens-4,lens);
    if(extname!=".jpg" && extname!=".gif")
    {
    alert("请选择jpg或gif文件!");
    return (false);
    }
    }

}

</script>
</head>

<body leftmargin="0" topmargin="0" bgcolor="#CEDBFF">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<form name="myform" method="post" action="upfile2.asp" enctype="multipart/form-data" language="javascript" onSubmit="return check();">
          <tr align="center" valign="middle">
            <td height="15" align="left"> 选择图片:
              <input type="file" name="file1" value=""> <input type="submit" value="上传" name="B1" class="txt " isshowprocessbar="True"></td>
          </tr>
      </form>
        </table>
</body>
</html>
====================================================================================
save3.asp 文件名

<%@ codepage ="936" %>
<!--#include file="conn.asp"-->
<%
pic2=request("pic2")
set res=server.CreateObject("adodb.recordset")
sql="select * from fwxmb where fwxm_id="&request("fwxm_id")
res.open sql,conn,1,3
res("pic2")=pic2
res.update
res.close
conn.close
response.redirect("gx.asp")
%>
====================================================================================
upfile2.asp 文件名
<!--#include FILE="upload.inc"-->
<html>
<head><title></title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#CEDBFF">
<%
nowtime=now()
sj=cstr(year(nowtime))+"-"+right("0"+cstr(month(nowtime)),2)+"-"+right("0"+cstr(day(nowtime)),2)
dim upload,file,formName,formPath,iCount,pic
set upload=new upload_f '建立上传对象
  '--------将日期转化成文件名--------
function MakedownName()
dim fname
   fname = now()
fname = replace(fname,"-","")
  fname = replace(fname," ","")
fname = replace(fname,":","")
   fname = replace(fname,"PM","")
   fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
   fname = replace(fname,"下午","")
   fname = int(fname) + int((10-1+1)*Rnd + 1)
MakedownName=fname
end function
formPath="../pic/"
iCount=0
for each formName in upload.file ''列出所有上传了的文件
 set file=upload.file(formName)  ''生成一个文件对象
 if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
newname=MakedownName()&"."&mid(file.FileName,InStrRev(file.FileName, ".")+1)

  file.SaveAs Server.mappath(formPath&newname)   ''保存文件
  iCount=iCount+1
 end if
next
response.write newname
%>
<script language="JavaScript">
parent.myform.pic2.value+='<%=newname%>';
</script>
<%
set file=nothing
set upload=nothing  ''删除此对象
%>
</body>
</html>
====================================================================================
zyok.JS 这是调用的JS不知道干啥用的
//***********默认设置定义.*********************
tPopWait=50;//停留tWait毫秒后显示提示。
tPopShow=3000;//显示tShow毫秒后关闭提示
showPopStep=20;
popOpacity=99;
//***************内部变量定义*****************
sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;
document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText { background-color: #ffffff; border: 1px #000000 solid; font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id='zzzpopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");
function showPopupText(){
var o=event.srcElement;
MouseX=event.x;
MouseY=event.y;
if(o.alt!=null && o.alt!=""){o.zzzpop=o.alt;o.alt=""};
if(o.title!=null && o.title!=""){o.zzzpop=o.title;o.title=""};
if(o.zzzpop!=sPop) {
sPop=o.zzzpop;
clearTimeout(curShow);
clearTimeout(tFadeOut);
clearTimeout(tFadeIn);
clearTimeout(tFadeWaiting);
if(sPop==null || sPop=="") {
zzzpopLayer.innerHTML="";
zzzpopLayer.style.filter="Alpha()";
zzzpopLayer.filters.Alpha.opacity=0;
}
else {
if(o.dyclass!=null) popStyle=o.dyclass
else popStyle="cPopText";
curShow=setTimeout("showIt()",tPopWait);
}
}
}
function showIt(){
zzzpopLayer.className=popStyle;
zzzpopLayer.innerHTML=sPop;
popWidth=zzzpopLayer.clientWidth;
popHeight=zzzpopLayer.clientHeight;
if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
else popLeftAdjust=0;
if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
else popTopAdjust=0;
zzzpopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
zzzpopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
zzzpopLayer.style.filter="Alpha(Opacity=0)";
fadeOut();
}
function fadeOut(){
if(zzzpopLayer.filters.Alpha.opacity<popOpacity) {
zzzpopLayer.filters.Alpha.opacity+=showPopStep;
tFadeOut=setTimeout("fadeOut()",1);
}
else {
zzzpopLayer.filters.Alpha.opacity=popOpacity;
tFadeWaiting=setTimeout("fadeIn()",tPopShow);
}
}
function fadeIn(){
if(zzzpopLayer.filters.Alpha.opacity>0) {
zzzpopLayer.filters.Alpha.opacity-=1;
tFadeIn=setTimeout("fadeIn()",1);
}
}
document.onmouseover=showPopupText;
====================================================================================
upload.inc 文件名
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

dim upfile_Stream

Class upload_F
  
dim Form,File,Version
  
Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version=""
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_Stream=CreateObject("Adodb.Stream")
upfile_Stream.mode=3
upfile_Stream.type=1
upfile_Stream.open
upfile_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
  iStart=inString(iFormStart,"name=""")
  iEnd=inString(iStart+6,"""")
  mFormName=subString(iStart+6,iEnd-iStart-6)
  iFileNameStart=inString(iEnd+1,"filename=""")
  if iFileNameStart>0 and iFileNameStart<iFormEnd then
   iFileNameEnd=inString(iFileNameStart+10,"""")
   mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
   iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
   iEnd=inString(iStart+4,vbEnter&strDiv)
   if iEnd>iStart then
    mFileSize=iEnd-iStart-4
   else
    mFileSize=0
   end if
   set theFile=new FileInfo
   theFile.FileName=getFileName(mFileName)
   theFile.FilePath=getFilePath(mFileName)
   theFile.FileSize=mFileSize
   theFile.FileStart=iStart+4
   theFile.FormName=FormName
   file.add mFormName,theFile
  else
   iStart=inString(iEnd+1,vbEnter&vbEnter)
   iEnd=inString(iStart+4,vbEnter&strDiv)

   if iEnd>iStart then
    mFormValue=subString(iStart+4,iEnd-iStart-4)
   else
    mFormValue=""
   end if
   form.Add mFormName,mFormValue
  end if

  iFormStart=iformEnd+iDivLen
  iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
 dim i,c,stemp
 upfile_Stream.Position=theStart-1
 stemp=""
 for i=1 to theLen
   if upfile_Stream.EOS then Exit for
   c=ascB(upfile_Stream.Read(1))
   If c > 127 Then
    if upfile_Stream.EOS then Exit for
    stemp=stemp&Chr(AscW(ChrB(AscB(upfile_Stream.Read(1)))&ChrB(c)))
    i=i+1
   else
    stemp=stemp&Chr(c)
   End If
 Next
 subString=stemp
End function

Private Function inString(theStart,varStr)
 dim i,j,bt,theLen,str
 InString=0
 Str=toByte(varStr)
 theLen=LenB(Str)
 for i=theStart to upfile_Stream.Size-theLen
   if i>upfile_Stream.size then exit Function
   upfile_Stream.Position=i-1
   if AscB(upfile_Stream.Read(1))=AscB(midB(Str,1)) then
    InString=i
    for j=2 to theLen
      if upfile_Stream.EOS then
        inString=0
        Exit for
      end if
      if AscB(upfile_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
        InString=0
        Exit For
      end if
    next
    if InString<>0 then Exit Function
   end if
 next
End Function

Private Sub Class_Terminate  
  form.RemoveAll
  file.RemoveAll
  set form=nothing
  set file=nothing
  upfile_Stream.close
  set upfile_Stream=nothing
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

 Private function toByte(Str)
   dim i,iCode,c,iLow,iHigh
   toByte=""
   For i=1 To Len(Str)
   c=mid(Str,i,1)
   iCode =Asc(c)
   If iCode<0 Then iCode = iCode + 65535
   If iCode>255 Then
     iLow = Left(Hex(Asc(c)),2)
     iHigh =Right(Hex(Asc(c)),2)
     toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
   Else
     toByte = toByte & chrB(AscB(c))
   End If
   Next
 End function
End Class


Class FileInfo
  dim FormName,FileName,FilePath,FileSize,FileStart
  Private Sub Class_Initialize
    FileName = ""
    FilePath = ""
    FileSize = 0
    FileStart= 0
    FormName = ""
  End Sub
  
 Public function SaveAs(FullPath)
    dim dr,ErrorChar,i
    SaveAs=1
    if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
    if FileStart=0 or right(fullpath,1)="/" then exit function
    set dr=CreateObject("Adodb.Stream")
    dr.Mode=3
    dr.Type=1
    dr.Open
    upfile_Stream.position=FileStart-1
    upfile_Stream.copyto dr,FileSize
    dr.SaveToFile FullPath,2
    dr.Close
    set dr=nothing
    SaveAs=0
  end function
End Class
</SCRIPT>
===============================================================================================
这是修改提交页 学习中代码很乱
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<!--#include file="checkUser.asp"-->
<%
dim fwxm_id
fwxm_id=request("fwxm_id")
set res=server.CreateObject("adodb.recordset")
sql="select * from fwxmb where fwxm_id="&fwxm_id
res.open sql,conn,1,1
if not res.eof then
%>
<html>
<head>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>

<STYLE type=text/css>
TD {
COLOR: #000; FONT-FAMILY: 宋体; FONT-SIZE: 12px
}
.GR {
COLOR: #666
}
</STYLE>
<script LANGUAGE="JavaScript">
function check()
{
if (document.myform.xs_id.value=="")
{
alert("请选择产品类别")
return
}

document.myform.submit()
}
</SCRIPT>

<SCRIPT language=javascript src="zyok.JS"></SCRIPT>
</head>
<BODY text=#000000 leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" bgcolor="#F7FBFF">
<div align="center">
<TABLE cellSpacing=0 cellPadding=0 width="99%" bgColor=#ffffff border=0 style="border-collapse: collapse" bordercolor="#111111">
<TBODY>
<tr>
<TD align=middle>
<CENTER>
<TABLE border=0 cellSpacing=0 width="100%" style="border-collapse: collapse" height="505" cellpadding="0">
<TR><TD width="100%" height="34" bgcolor="#EEF7FF">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1" height="22">
<tr>
<TD width="770" height="34">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="558" id="AutoNumber1" height="22">
<tr>
<td width="1" valign="bottom">
</td>
<td width="116" background="images/b4.gif" height="22">&nbsp;<img src="IMAGES/cl1.gif" width="13" height="11" border="0">
<b>产品发布</b></td>
<td width="441">
<p align="right"><font color="#FF0000">注:请不要发布重复产品
</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor=999999></td>
</tr>
</table></TD>
</tr>
</table>
</td>
</tr>
</table></TD>
</TR>
<form method="POST" action="save3.asp?page=<%=request("page")%>&fwxm_id=<%=fwxm_id%>" name="myform">
<TR><TD width="100%" valign="top" bgcolor="#EEF7FF">
  <table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">
                      <tr>
                        <TD colspan="2" height="20" bgcolor="#EEF7FF" width="772">
                          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
                            <tr>
                              <TD height="17" bgcolor="#EEF7FF" width="770"> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
                                  <tr>
                                    <td width="84%"><span style="font-size: 10.5pt"><b>&nbsp;<img src="IMAGES/bul_arrowGrnSm.gif" width="12" height="12" border="0">
                                      产品信息</b></span></td>
                                    <td width="16%"> <p align="left"><font color="#FF6600">&nbsp;*</font><font color="#000080">为必填项
                                        </font> </td>
                                  </tr>
                                </table></TD>
                            </tr>
                          </table></TD>
                      </tr>
                      <tr>
                        <TD align="right" height="23" bgcolor="#EEF7FF">行业类别:</TD>
                        <TD height="23" bgcolor="#EEF7FF"> &nbsp;
                          <select name="xs_id" id="xs_id" title="请选择产品类别">
                            <% set rs=server.createobject("adodb.recordset")
   sql="select * from fwxmb"
   rs.open sql,conn,1,1
   do while not rs.eof
%>
                            <option value="<%=rs("xs_id")%>" <%if res("xs_id")=rs("xs_id") then response.write "selected"%>><%=rs("xs_id")%></option>
                            <% rs.movenext
   loop
   rs.close
   set rs=nothing
%>
                          </select> </td>
                      </tr>
                      <tr>
                        <TD align="right" height="25" bgcolor="#CEDBFF">产品放大图:</td>
                        <TD height="25" bgcolor="#CEDBFF">&nbsp; <INPUT name=pic2 type=hidden value="<%=res("pic2")%>">
                          <iframe marginwidth=0 framespacing=0 marginheight=0 frameborder=0 width="350" height=25 src="picture2.asp"></iframe>
                          &nbsp;<font color="#FF6600">&nbsp;*(注:图片大小不得超过500KB,如无须修改图片请不要上传)</font></td>
                      </tr>
                      <tr bgcolor="#EEF7FF">
                        <TD colspan="2" align="right" bgcolor="#EEF7FF">&nbsp;</TD>
                      </tr>
                      <tr>
                        <TD colspan="2" align="center" height="21" bgcolor="#CEDBFF">
                          <INPUT  type="button" value="确 定" onClick="check()">
                          &nbsp;&nbsp;&nbsp;&nbsp;
                          <INPUT  type="button" value="返 回">
                        </TD>
                      </tr>
                      <tr>
                        <TD colspan="2" align="center" height="12" bgcolor="#EEF7FF"></TD>
                      </tr>
                    </table>
</TD></TR>
</FORM>
</TABLE>
</CENTER></TD>
</tr>
</TBODY></TABLE>
</div>
</body>
</html>
<% end if
   res.close
   set res=nothing
   conn.close
   set conn=nothing
 %>
====================================================================================
跪求各位高手帮我看看是哪出问题了
搜索更多相关主题的帖子: javascript content 数据库 title 图片 
2013-10-07 00:31
qiage777
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-7
得分:0 
这是问题现象图片
2013-10-07 00:32
qiage777
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-7
得分:0 
<%
nowtime=now()
sj=cstr(year(nowtime))+"-"+right("0"+cstr(month(nowtime)),2)+"-"+right("0"+cstr(day(nowtime)),2)
dim upload,file,formName,formPath,iCount,pic
set upload=new upload_f '建立上传对象
     '--------将日期转化成文件名--------
    function MakedownName()
        dim fname
          fname = now()
        fname = replace(fname,"-","")
         fname = replace(fname," ","")
        fname = replace(fname,":","")
          fname = replace(fname,"PM","")
          fname = replace(fname,"AM","")
        fname = replace(fname,"上午","")
          fname = replace(fname,"下午","")
          fname = int(fname) + int((10-1+1)*Rnd + 1)
        MakedownName=fname
    end function
formPath="../pic/"
iCount=0
for each formName in upload.file ''列出所有上传了的文件
 set file=upload.file(formName)  ''生成一个文件对象
 if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
newname=MakedownName()&"."&mid(file.FileName,InStrRev(file.FileName, ".")+1)

  file.SaveAs Server.mappath(newname)   ''保存文件
  iCount=iCount+1
 end if
next
response.write newname
%>
<script language="JavaScript">
parent.myform.pic2.value+='<%=newname%>';
</script>
<%
set file=nothing
set upload=nothing  ''删除此对象
%>
2013-10-07 11:19
qiage777
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-7
得分:0 
  file.SaveAs Server.mappath(newname)   ''保存文件
换为newname 可是效果还是一样的 没有更新 只有叠加写入。。。。。。。
2013-10-07 11:20
qiage777
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-7
得分:0 
谁帮帮忙啊
2013-10-07 12:01
qiage777
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-7
得分:0 
有没有热心人帮帮忙啊
2013-10-07 13:18
qiage777
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-7
得分:0 
百度知道 QQ问问 各大ASP网站都问了 没一个能解决的 看来这是世界难题了
2013-10-07 13:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-421509-1-1.html




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

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