CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  ASP

关于ASP页面中图片文件上传的问题?来者有分!!!

楼主GoWish(GoWish)2005-04-04 15:42:37 在 Web 开发 / ASP 提问

在ASP页面中如何实现图片的上传,使用有组件和无组件的方法怎么实现?哪种方法更好?  
  请给段code举例,谢谢! 问题点数:100、回复次数:19Top

1 楼lstup(流水)回复于 2005-04-04 15:47:54 得分 1

化境,一直用得挺顺手,不用担心服务器问题Top

2 楼lstup(流水)回复于 2005-04-04 15:54:42 得分 1

code网上自己down,Top

3 楼hbhbhbhbhb1021(天外水火(我要多努力))回复于 2005-04-04 15:55:42 得分 20

lyfupload组件,你到网上搜下好多,自代教程  
  给你个例子,4个文件,这个组件服务器要注册的,需要注意的是不能用request方法了,要用组件带的那个request方法  
   
  1.asp  
  <form   method="POST"   enctype="multipart/form-data"   action="demo4.asp">  
  <p>文本框1:   <input   type="text"   name="text1"   size="20"><br>  
  选择文件:<input   type="file"   name="file1"><br>  
  <input   type="submit"   value="上载"   style="background-color:   rgb(0,0,255);   color:   rgb(255,255,0)">   </p>  
  </form>  
   
  demo4.asp  
   
  <%@Language=VBScript   %>  
  <%  
          FormSize   =   Request.TotalBytes  
          FormData   =   Request.BinaryRead(   FormSize   )  
           
          bncrlf=chrb(13)   &   chrb(10)  
          divider=leftb(formdata,instrb(formdata,bncrlf)-1)  
          datastart=instrb(formdata,bncrlf   &   bncrlf)+4  
          dataend=instrb(datastart+1,formdata,divider)-datastart  
          Image=midb(formdata,datastart,dataend)  
   
          head_version   =   Ascb(   midb(   Image,1,3   )   )  
          head_subversion   =   Ascb(   midb(   Image,4,3   )   )  
   
          head_width_l   =   Ascb(   midb(   Image,7,1   )   )  
          head_width_h   =   Ascb(   midb(   Image,8,1   )   )  
   
          head_height_l   =   Ascb(   midb(   Image,9,1   )   )  
          head_height_h   =   Ascb(   midb(   Image,10,1   )   )  
   
          head_colors   =   Ascb(   midb(   Image,   11,   1   )   )  
   
          head_width_h   =   head_width_h   *   256  
           
          head_height_h   =   head_height_h   *   256  
           
           
          head_colors   =   head_colors   And   &H07  
   
          Response.Write   "图像大小为"   &   head_width_h   +   head_width_l   &   "x"   &   head_height_h   +   head_height_l   &   "x"   &     2^(   head_colors   +   1   )  
   
  '设置数据库链接  
  strConn   =   "Provider=SQLOLEDB.1;Password=sa;Persist   Security   Info=True;User   ID=sa;Initial   Catalog=jishu;Data   Source=RD03"        
  session("strconn")=strConn  
  Set   dbc   =   Server.CreateObject("ADODB.Connection")  
  dbc.open   strConn  
  set   rs=server.CreateObject("adodb.recordset")  
  rs.Open   "SELECT   *   FROM   product",dbc,1,3  
  %>  
  <HTML>        
  <BODY>        
  <%  
  Set   obj   =   Server.CreateObject("LyfUpload.UploadFile")  
  obj.maxsize=2048     '设置文件上传的最大为2048个字节(2K)  
  obj.extname="gif"  
  txt   =   obj.request("text1")   '得到form元素的值  
  Response.Write(   "文本框1的输入值是:   "   &   txt)          
  Response.Write   "<br>"  
  ss=obj.SaveFiletodb("file1")   '保存文件到服务器  
  aa=obj.filetype("file1")   '得到文件的Content-Type  
   
   
  if   ss=   ""   then  
    Response.Write   ("文件上传失败!")  
  elseif   ss=   "0"     then  
        Response.Write   ("文件尺寸过大!")  
  elseif   ss=   "1"   then  
    Response.Write   ("文件不是gif文件!")  
  else  
  '----文件上载到数据库中---------  
  rs.AddNew  
  rs("name")=trim(aa)  
  rs("pic").AppendChunk   obj.DBContent'BLOB数据不能直接赋值  
  rs.Update    
  rs.movelast  
  session("ID")=rs("ID")  
  rs.Close    
  dbc.Close    
  set   rs=nothing  
  set   dbc=nothing        
  '------------------------------上载到数据库中结束  
  Response.Write   "选择的文件已经上载到服务器!<br>"    
  Response.Write("文件名:"   &   ss)      
  Response.Write("<br>Content-Type:"   &   aa)   '得到Content-Type  
  Response.Write("文件大小:"   &   obj.FileSize)      
  end   if  
   
  obj.about       '关于LyfUploa1.0  
  %>  
  <br>  
  <a   href="pictest.asp?ID=<%=session("ID")%>">点击此处查看上传后数据库中的GIF文件!</a>  
    </BODY   >  
    </html>  
   
  pictest.asp  
  <%  
  Function   SetForDisplay(field,   contentType)  
         
          contentType   =   contentType  
                          nFieldSize   =   field.ActualSize  
  bytes   =   field.GetChunk(nFieldSize)  
         
          Session("Bytes")   =   bytes  
          Session("Type")   =   contentType  
  End   Function  
  %>  
   
  <%  
        sql   =   "select   *   from   product   where   id="   &   request("ID")  
        Set   oRS   =   Server.CreateObject("ADODB.Recordset")  
        oRS.CursorLocation   =   3  
        strConn   =   "Provider=SQLOLEDB.1;Password=sa;Persist   Security   Info=True;User   ID=sa;Initial   Catalog=jishu;Data   Source=RD03"      
        oRS.Open   sql,   strConn  
             
        SetForDisplay   oRS("pic"),   "image/gif"   '"image/gif"   为MIME类型  
  '常见文件的MIME类型  
  'GIF文件     "image/gif"  
  'BMP文件   "image/bmp"  
  'JPG文件   "image/jpeg"  
  'zip文件   "application/x-zip-compressed"  
  'DOC文件   "application/msword"  
  '文本文件   "text/plain"  
  'HTML文件   "text/html"  
  '一般文件   "application/octet-stream"  
          Set   oRS.ActiveConnection   =   Nothing  
  %>  
  <img   src="theImg.asp">  
  <%response.write(Session("Type"))%>  
   
  theImg.asp  
  <%    
          '   theImg.asp   proxy   page    
          response.Expires   =   0  
          response.Buffer     =   True  
          response.Clear  
          response.contentType   =   Session("Type")  
          'Response.Write(Session("ImageBytes"))  
          response.BinaryWrite   Session("Bytes")  
          Session("Type")   =   ""  
          Session("Bytes")   =   ""  
          response.End  
  %>  
   
   
   
  Top

4 楼GoWish(GoWish)回复于 2005-04-04 16:00:27 得分 0

最好给段无组件上传的方法,谢谢Top

5 楼netter2003(我知道错了,以后我会及时结贴。)回复于 2005-04-04 16:24:43 得分 47

无组件一传我有:  
   
  <SCRIPT   RUNAT=SERVER   LANGUAGE=VBSCRIPT>  
   
  dim   upfile_5xSoft_Stream  
   
  Class   upload_5xSoft  
       
  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="深圳   Version   1.0"  
  if   Request.TotalBytes<1   then   Exit   Sub  
  set   Form=CreateObject("Scripting.Dictionary")  
  set   File=CreateObject("Scripting.Dictionary")  
  set   upfile_5xSoft_Stream=CreateObject("Adodb.Stream")  
  upfile_5xSoft_Stream.mode=3  
  upfile_5xSoft_Stream.type=1  
  upfile_5xSoft_Stream.open  
  upfile_5xSoft_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_5xSoft_Stream.Position=theStart-1  
    stemp=""  
    for   i=1   to   theLen  
        if   upfile_5xSoft_Stream.EOS   then   Exit   for  
        c=ascB(upfile_5xSoft_Stream.Read(1))  
        If   c   >   127   Then  
          if   upfile_5xSoft_Stream.EOS   then   Exit   for  
          stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_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_5xSoft_Stream.Size-theLen  
        if   i>upfile_5xSoft_Stream.size   then   exit   Function  
        upfile_5xSoft_Stream.Position=i-1  
        if   AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1))   then  
          InString=i  
          for   j=2   to   theLen  
              if   upfile_5xSoft_Stream.EOS   then    
                  inString=0  
                  Exit   for  
              end   if  
              if   AscB(upfile_5xSoft_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_5xSoft_Stream.close  
      set   upfile_5xSoft_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_5xSoft_Stream.position=FileStart-1  
          upfile_5xSoft_Stream.copyto   dr,FileSize  
          dr.SaveToFile   FullPath,2  
          dr.Close  
          set   dr=nothing    
          SaveAs=0  
      end   function  
  End   Class  
  </SCRIPT>Top

6 楼netter2003(我知道错了,以后我会及时结贴。)回复于 2005-04-04 16:29:12 得分 10

使用方法补充:  
  SavePath="upcpimage/"  
  set   upload=new   upload_5xsoft  
  set   file=upload.file("file1")  
  if   file.filesize>0   then  
  fileext=right(file.filename,3)  
  if   fileext="asp"   or   fileext="asa"   or   fileext="aspx"     then  
  response.write"<script>alert('此类文件不能上传');history.back();</script>"  
  response.End  
  end   if  
  randomize  
  ranNum=int(900*rnd)+100  
  filename=SavePath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt  
  file.Saveas   Server.mappath(FileName)    
  '//////////////////////////////////////////////////  
  file1为文件域的名称Top

7 楼lstup(流水)回复于 2005-04-04 17:04:35 得分 1

http://www.37zz.com/ShowPost.asp?id=101  
   
  就是化境了啦。  
  Top

8 楼GoWish(GoWish)回复于 2005-04-04 17:30:22 得分 0

to   netter2003(心里好烦):  
  Class   upload_5xSoft   是不是组件类呀?Top

9 楼richwong(QQ:1856856)回复于 2005-04-04 17:38:45 得分 1

Class   upload_5xSoft    
  乃无组上传类Top

10 楼kkkbs(邂逅浪漫)回复于 2005-04-04 17:48:03 得分 1

嗯嗯...无组件Class   upload_5xSoft  
  Top

11 楼lstup(流水)回复于 2005-04-04 17:51:40 得分 1

to   netter2003(心里好烦):  
  Class   upload_5xSoft   是不是组件类呀?  
  ==========  
  我不是说了吗?  
  就是化境Top

12 楼coolwindkaka(寒の风)回复于 2005-04-04 18:00:12 得分 1

大把的无组件上传工具Top

13 楼GoWish(GoWish)回复于 2005-04-07 16:33:33 得分 0

在使用lyfupload组件上传时遇到困难,请各位帮忙解答:  
  1.asp  
  <%@   Language=VBScript%>  
  <HTML>  
  <HEAD>  
  <META   NAME="GENERATOR"   Content="Microsoft   Visual   Studio   6.0">  
  <META   HTTP-EQUIV="content-type"   CONTENT="text/html;charset=Shift_JIS">  
  <META   http-equiv="Content-Style-Type"   CONTENT="text/css">  
  <TITLE></TITLE>  
  </HEAD>  
  <BODY>  
  <form   name="form1"   id="form1"   action="ftpUpLoadWrite.asp"   method=post   ENCTYPE="multipart/form-data">  
  <input   type="text"   name="text"   id="text"><input   type="button"   value="変   更"   onClick="file.click();text.value=file.value;">  
  <input   type=hidden   name="hidPath"   id="hidPath"   value="">  
  <br>  
  <br>  
  <input   type="file"   name="file"   id="file">  
  <input   type="button"   name="sub"   id="sub"   value="UpLoad"   onclick="window.document.form1.submit()">  
  </form>  
  </BODY>  
  </HTML>  
   
  2.ftpUpLoadWrite.asp  
  <%  
  Set   obj   =   Server.CreateObject("LyfUpload.UploadFile")  
  txt   =   obj.Request("text")  
  Response.Write(txt)  
  ss   =   obj.SaveFile("file","c:\temp",true)  
  aa   =   obj.FileType("file")  
  if   ss   <>   ""   then  
          Response.Write("sucess")  
  else  
          Response.Write("fail")  
  end   if  
  %>  
  <HTML>  
  <HEAD>  
  <META   HTTP-EQUIV="content-type"   CONTENT="text/html;charset=Shift_JIS">  
  <META   http-equiv="Content-Style-Type"   CONTENT="text/css">  
  <META   NAME="GENERATOR"   Content="Microsoft   Visual   Studio   6.0">  
  <TITLE></TITLE>  
  </HEAD>  
  <BODY>  
  <%  
  %>UpLoad!  
  </BODY>  
  </HTML>  
  upLoad时报错,报错信息为"ACCESS   拒绝处理"Top

14 楼underone(再看抽你小丫的)回复于 2005-04-07 16:41:28 得分 5

你为什么不用无组件的呢  
  个人认为无组件的好Top

15 楼hanjie28()回复于 2005-04-07 17:58:39 得分 5

我认为无组件好!  
  第一:效率不错!第二:不用担心服务器问题!第三:还是免费的!  
   
  风声无组件上传类V2.0  
   
  我一直在用!效果不错!可以加我QQ   3100974,我把例子给你传给你!  
  Top

16 楼aspnetonline(耗子)回复于 2005-04-07 21:38:39 得分 1

down   netTop

17 楼GoWish(GoWish)回复于 2005-04-08 15:17:11 得分 0

我想使用一个text和一个butto控件来代替file控件的实现效果,主要是因为按键名称要改为  
  "変   更",如下:  
  <input   type="text"   name="text"   id="text">  
  <input   type="button"   value="変   更"   onClick="file.click();text.value=file.value;">  
  <input   type="file"   name="file"   id="file"   style="display:none">  
  但是在提交时,file.value确为"",不能正常上传文件,哪位帮忙解决,谢谢!!!  
   
  使用upload_5xsoft上传.  
  ----------------------------------------------  
  提交页面的代码如下:  
  <%OPTION   EXPLICIT%>  
  <%Server.ScriptTimeOut=5000%>  
  <!--#include   FILE="upload_5xsoft.inc"-->  
  <html>  
  <head>  
  <title></title>  
  </head>  
  <body>  
  <br><hr   size=1   noshadow   width=300   align=left><br><br>  
  <%  
  dim   upload,file,formName,formPath,iCount  
  set   upload=new   upload_5xsoft  
   
  if   upload.form("filepath")=""   then  
    set   upload=nothing  
  else  
    formPath=upload.form("filepath")  
    if   right(formPath,1)<>"\"   then   formPath=formPath&"\"    
  end   if  
   
  iCount=0  
  for   each   formName   in   upload.objForm  
    response.write   "form:"   &   formName   &"="   &upload.form(formName)&"<br>"  
  next  
   
  for   each   formName   in   upload.objFile  
    set   file=upload.file(formName)  
    if   file.FileSize>0   then  
      response.write   file.FilePath&file.FileName&"   ("&file.FileSize&")   =>   "&formPath&File.FileName&"!<br>"  
      file.SaveAs   formPath&file.FileName  
      iCount=iCount+1  
    end   if  
    set   file=nothing  
  next  
   
  set   upload=nothing  
  %>  
  </body>  
  </html>Top

18 楼GoWish(GoWish)回复于 2005-04-08 16:00:16 得分 0

在线等,请大家帮忙解决,谢谢!!!Top

19 楼tyhn168(it人)回复于 2005-04-08 16:31:23 得分 5

用化境上传!要源代码的话请QQ我:273308641,实现效果如:  
  http://www.puworld.org/pu/product_add.asp  
   
  可以直接用,不过这样做你什么都学不到,拿去研究研究吧!Top

相关问题

  • 初级问题:如何在asp页面上显示图片(已知图片文件的路径)
  • asp文件调aspx页面问题
  • ASP页面如何取得本页面文件框的值?
  • 请问如何在页面显示 .swf图片文件,谢谢!
  • 如何读取一个图片文件并网页面输出
  • 请各位高高手帮我解决一下,如何用ASP来上传图片文件到数据库,并且在页面上显示出来!
  • 急!!!!!100分问ASP页面如何取得本页面文件框的值?
  • 用ASP传图片文件进SQL Server
  • 怎样用asp将页面存成文本文件?
  • 如何在asp页面中调用dll文件

关键词

得分解答快速导航

  • 帖主:GoWish
  • lstup
  • lstup
  • hbhbhbhbhb1021
  • netter2003
  • netter2003
  • lstup
  • richwong
  • kkkbs
  • lstup
  • coolwindkaka
  • underone
  • hanjie28
  • aspnetonline
  • tyhn168

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo