在线情况
楼主
  • 头像
  • 风寂去清
  • 级别
    • 银两311
    • 经验2173
    • 文章102
    • 注册2005-03-18
    [求助]ASP学习时遇到的问题
    各位大哥,请帮帮我吧.
    我在后台传图片时,提示如下问题:

    Microsoft VBScript 编译器错误 错误 '800a03f6'

    缺少 'End'

    /iisHelp/common/500-100.asp,行242

    服务器对象 错误 'ASP 0177 : 800401f3'

    Server.CreateObject 失败

    /admin/Inc/upload_Image.asp,行30

    无效的 ProgID。



    源码如下:红色区域为错误地点


    <!--#include file = "../Inc/lib.asp" -->
    <!--#include file = "../Inc/Imglib.asp" -->
    <%
    function GetExtendName(FileName)
         dim ExtName
         I = InstrRev(FileName,".")
         ExtName = Right(FileName,len(FileName)-I)
         GetExtendName = ExtName
    end function

    function GetMainName(FileName)
         dim MainName
         'Response.Write FileName
         'Response.End
         I = InstrRev(FileName,".")
         MainName = Left(FileName,I-1)
         GetMainName = MainName
    end function

    iname = Request.QueryString("iname")
    if iName="" then
         call MsgBox("将保存的相对路径名称不能为空",1)
    End If

    If Request.ServerVariables("REQUEST_METHOD") = "POST" and Request.QueryString("type")<>"" Then
         'Response.End
         call CreateDIR(Application("SourceIMG"))

         Set Fs               = Server.CreateObject("scripting.filesystemobject")
         [COLOR=red]Set objUpload  = Server.CreateObject("aspcn.upload")[/COLOR]      ImgDirectory   = Server.MapPath(Application("SourceIMG"))

         SavedFileName        =  Cstr(NowFlag) & ".jpg" '& GetExtendName(UpLoadFileName)
         TempFileName        =  Cstr(NowFlag) & ".tmp"
         
         Tfile = server.MapPath(Application("SourceIMG")& TempFileName)
         ufile = server.MapPath(Application("SourceIMG")& SavedFileName)

         objupload.maxsize      = Application("MaxUpLoadImgSize")      '设定文件最大长度不超过100K,默认值为100K
         objupload.overwrite      = 2                        '设定如果目标文件存在,进行覆盖,默认为1,表示不能覆盖      
         objupload.path            = ImgDirectory      '设定上传到服务器的路径,这里必须为绝对路径,默认值为c:\\

         objupload.uptofile      = 1                        '设置为上传后保存为文件
         objUpload.NewFileName =  TempFileName

         varResult = objUpload.Upload            '调用upload方法将文件保存
         'ExtName            = GetExtendName(objupload.filename("Img"))
         
         If varResult<>"OK" Then                        '如果varResult返回OK,则文件上载成功
               Call Msgbox("上传失败!",1)
         End If
           Size = objUpload.size("file1")

           '这里处理图片的大小.如果是小图的话,就处理,如果是大图的话,就不处理.
           SImg = Tfile
           DImg = ufile
           
           ImgWidth = Application("ImgSmallWidth")
           ImgHeight= Application("ImgSmallHeight")

           If Lcase(iName) = "small_pic" then
               Call ProcessImg(SImg,DImg,ImgWidth,ImgHeight)
           Else
               Call Fs.CopyFile(SImg,DImg)
           End IF
           
           Call delFile(Application("SourceIMG")& TempFileName)
           'Call delVFile(SImg)

           set objUpload = nothing
           Set Fs            = nothing

           NewsID        = Trim(Session("newsID"))
           Filelink        = Application("SourceIMG") & SavedFileName
           FileName        = SavedFileName
         %>      
            <script language="javascript">
               if(parent.document.all.path){parent.document.all.path.value = '<%=FileLink%>';}
               if(parent.document.all.size){parent.document.all.size.value = '<%=size%>';}
               if(parent.document.all.imgpath){parent.document.all.imgpath.src  = '<%=FileLink%>';}
               //alert(parent.document.form1.<%=iname%>.value);
               history.back();
            </script>
         <%
    Response.End
    end if
    %>

    <style type="text/css">
    A:visited {COLOR: #000000; TEXT-DECORATION: none}
    A:active {COLOR: #000000; TEXT-DECORATION: none}
    A:link {COLOR: #000000; TEXT-DECORATION: none}
    A:hover {COLOR: #ff6600; text-deroration: none}
    .text
    {
        FONT-SIZE: 9pt
        COLOR: #000000;
        FONT-FAMILY: 宋体;
        TEXT-DECORATION: none
    }
    TABLE,td {FONT-SIZE: 9pt}

    .stinput
    {      BORDER-TOP-WIDTH: 1px;
         PADDING-RIGHT: 1px;
         PADDING-LEFT: 1px;
         BORDER-LEFT-WIDTH: 1px;
         FONT-SIZE: 10.5pt;
         BORDER-LEFT-COLOR: #cccccc;
         BORDER-BOTTOM-WIDTH: 1px;
         BORDER-BOTTOM-COLOR: #cccccc;
         PADDING-BOTTOM: 1px;
         BORDER-TOP-COLOR: #cccccc;
         PADDING-TOP: 1px;
         BORDER-RIGHT-WIDTH: 1px;
         BORDER-RIGHT-COLOR: #cccccc;
         HEIGHT: 22px;
         FONT-FAMILY: 宋体;
    }
    </style>

    <body topmargin=0 leftmargin=0 bgcolor=#EFEFEF>

    <table border=0 width=100%  cellpadding=1 cellspacing=0 height=100%>
    <FORM action="upload_Image.asp?type=save&iname=<%=iname%>" id=form2 method=post name=form2 enctype="multipart/form-data" target="_self">
    <tr><td align=left><input type=file  size="9"  name="file1" class=stinput>
     <input type=submit class=stinput value="上传" id=button1 name="supload">
     </td></tr>
     </form></table>
     
    有限人生有无限可能,转个弯你会发现不同风景
    在线情况
    2
    • 头像
    • 侠之大者
    • 级别
    • 门派
    • 会员认证会员
    • 声望+1
    • 财富115
    • 银两1383
    • 经验39591
    • 文章1360
    • 注册2004-03-27
    是不是路径不对,上传到什么文件夹名称
    青青子衿,悠悠我心。纵我不往,子宁不嗣音?青青子佩,悠悠我思。纵我不往,子宁不来?挑兮达兮,在城阙兮。一日不见,如三月兮。
    [img]http://www.new-adhesive.com/img/20041125110961.jpg[/img]
    在线情况
    3
    • 头像
    • 人去茶凉情已殇
    • 级别
    • 门派
    • 财富155
    • 银两32
    • 经验28198
    • 文章8774
    • 注册2005-08-07
    2楼的,你是不是网络高手啊
    [img]http://www.binok.com/bbs/images/upload/2006/05/24/151759.jpg[/img]
    梦想着有一天,带着你,远离城市的喧嚣,抱着你,坐在离天边最近的地方,欣赏我们自己的风景
    在线情况
    4
    • 头像
    • 级别
      • 银两11865
      • 经验473
      • 文章50
      • 注册2005-12-04
      Server.CreateObject 失败
      看看你定义的变量名是否正确
      源代码应该没什么问题(我没仔细看),你对照一下
      [GLOW=255,RED,2]走廊上迎面来了个PLMM冲我打招待:哇,帅哥!我一记耳光飞上她脸庞,说道:靠,废话!![/GLOW]
      在线情况
      5
      • 头像
      • 离欲阿修罗
      • 级别
      • 门派
      • 声望+48
      • 财富102756
      • 银两1809175
      • 经验138295
      • 文章2275
      • 注册2004-06-26
      应该是不支持该组件(组件未注册)吧
      [imga]../images/upload/2006/10/14/203457.jpg[/imga]
      [imga]../images/upload/2006/10/14/203700.jpg[/imga]
      第一张叫做“执着”  尽管一只鸽子也没有 但她还是一直在努力
      第二张叫做“快乐”  仿佛 就要飞起来了  不是她的心已经飞起来了
      在线情况
      6
      • 头像
      • Μr.Lonely
      • 级别
        • 财富39
        • 银两73238
        • 经验6277
        • 文章589
        • 注册2005-09-17
        对不起,刚刚上任,以前不怎么来这个区,这么久了,不知问题解决了没有。

        这个是Server.CreateObject的用法
        混杂的煙味.微熏的嘴.
        在线情况
        7
        • 头像
        • Μr.Lonely
        • 级别
          • 财富39
          • 银两73238
          • 经验6277
          • 文章589
          • 注册2005-09-17
          <%

          dim oUpFileStream

          Class upload_file
           
          dim Form,File,Version
           
          Private Sub Class_Initialize
             '定义变量
            dim RequestBinDate,sStart,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
            dim iFileSize,sFilePath,sFileType,sFormvalue,sFileName
            dim iFindStart,iFindEnd
            dim iFormStart,iFormEnd,sFormName
             '代码开始
            Version="5757NET 专用"
            set Form = Server.CreateObject("Scripting.Dictionary")
            set File = Server.CreateObject("Scripting.Dictionary")
            if Request.TotalBytes < 1 then Exit Sub
            set tStream = Server.CreateObject("adodb.stream")
            set oUpFileStream = Server.CreateObject("adodb.stream")
            oUpFileStream.Type = 1
            oUpFileStream.Mode = 3
            oUpFileStream.Open
            oUpFileStream.Write Request.BinaryRead(Request.TotalBytes)
            oUpFileStream.Position=0
            RequestBinDate = oUpFileStream.Read
            iFormEnd = oUpFileStream.Size
            bCrLf = chrB(13) & chrB(10)
            '取得每个项目之间的分隔符
            sStart = MidB(RequestBinDate,1, InStrB(1,RequestBinDate,bCrLf)-1)
            iStart = LenB (sStart)
            iFormStart = iStart+2
            '分解项目
            Do
              iInfoEnd = InStrB(iFormStart,RequestBinDate,bCrLf & bCrLf)+3
              tStream.Type = 1
              tStream.Mode = 3
              tStream.Open
              oUpFileStream.Position = iFormStart
              oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
              tStream.Position = 0
              tStream.Type = 2
              tStream.Charset ="gb2312"
              sInfo = tStream.ReadText     
              '取得表单项目名称
              iFormStart = InStrB(iInfoEnd,RequestBinDate,sStart)-1
              iFindStart = InStr(22,sInfo,"name=""",1)+6
              iFindEnd = InStr(iFindStart,sInfo,"""",1)
              sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
              '如果是文件
              if InStr (45,sInfo,"filename=""",1) > 0 then
                set oFileInfo= new FileInfo
                '取得文件属性
                iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
                iFindEnd = InStr(iFindStart,sInfo,"""",1)
                sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
                oFileInfo.FileName = GetFileName(sFileName)
                oFileInfo.FilePath = GetFilePath(sFileName)
                oFileInfo.FileExt = GetFileExt(sFileName)
                iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
                iFindEnd = InStr(iFindStart,sInfo,vbCr)
                oFileInfo.FileType = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
                oFileInfo.FileStart = iInfoEnd
                oFileInfo.FileSize = iFormStart -iInfoEnd -2
                oFileInfo.FormName = sFormName
                file.add sFormName,oFileInfo
              else
              '如果是表单项目
                tStream.Close
                tStream.Type = 1
                tStream.Mode = 3
                tStream.Open
                oUpFileStream.Position = iInfoEnd
                oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2
                tStream.Position = 0
                tStream.Type = 2
                tStream.Charset = "gb2312"
                sFormvalue = tStream.ReadText
                form.Add sFormName,sFormvalue
              end if
              tStream.Close
              iFormStart = iFormStart+iStart+2
              '如果到文件尾了就退出
              loop until (iFormStart+2) = iFormEnd
            RequestBinDate=""
            set tStream = nothing
          End Sub

          Private Sub Class_Terminate  
            '清除变量及对像
            if not Request.TotalBytes<1 then
              oUpFileStream.Close
              set oUpFileStream =nothing
              end if
            Form.RemoveAll
            File.RemoveAll
            set Form=nothing
            set File=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 GetFileExt(FullPath)
            If FullPath <> "" Then
              GetFileExt = mid(FullPath,InStrRev(FullPath, ".")+1)
              Else
              GetFileExt = ""
            End If
          End function

          End Class

          '文件属性类
          Class FileInfo
            dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
            Private Sub Class_Initialize
              FileName = ""
              FilePath = ""
              FileSize = 0
              FileStart= 0
              FormName = ""
              FileType = ""
              FileExt = ""
            End Sub
           
          '保存文件方法
           Public function SaveToFile(FullPath)
              dim oFileStream,ErrorChar,i
              SaveToFile=1
              if trim(fullpath)="" or right(fullpath,1)="/" then exit function
              set oFileStream=CreateObject("Adodb.Stream")
              oFileStream.Type=1
              oFileStream.Mode=3
              oFileStream.Open
              oUpFileStream.position=FileStart
              oUpFileStream.copyto oFileStream,FileSize
              oFileStream.SaveToFile FullPath,2
              oFileStream.Close
              set oFileStream=nothing
              SaveToFile=0
            end function
          End Class
          %>
          这个你看看!  还有个ASP的实用论文要不要!
            这方面没什么研究,谅解!
          混杂的煙味.微熏的嘴.
          在线情况
          8
          • 头像
          • Μr.Lonely
          • 级别
            • 财富39
            • 银两73238
            • 经验6277
            • 文章589
            • 注册2005-09-17
            asp实现无组件上传图片到数据库并显示网页上



            用asp编写网站应用程序时间长了,难免会遇到各式各样的问题,其中

            关于如何上传文件到服务器恐怕是遇见最多的问题了,尤其是上传图片,比如

            你想要在自己的社区里面实现类似网易虚拟社区提供的“每日一星”的功能,

            就要提供给网友上传照片的功能。上传图片文件到服务器可以使用各种免费的

            文件上传组件,使用起来功能虽然很强大,但是由于很多情况下,我们只能使

            用免费的支持asp的空间或者租用别人的虚拟空间,对于第一种情况,我们

            根本就没有可能来使用文件上传组件;至于第二种情况,我们也要付出不少的

            “银子”才可以。除非你拥有自己的虚拟主机,你就可以随便的在服务器上面

            安装自己所需要的组件,这种情况对于大多数人来说是可望而不可及的。那我

            们就没有办法了吗?呵呵,答案是肯定的(当然是肯定的了,要不然我也没法

            写出这篇文章啊)。下面就让我们一起来使用纯asp代码来实现图片的上传

            以及保存到数据库的功能(顺便也实现显示数据库中的图片到网页上的功

            能)。

            首先我们先来熟悉一下将要使用的对象方法。我们用来获取上一个页面传

            递过来的数据一般是使用request对象。同样的,我们也可以使用request对象

            来获取上传上来的文件数据,使用的方法是request.binaryread()。而我们要从

            数据库中读出来图片的数据显示到网页上面要用到的方法是:

            request.binarywrite()。在我们得到了图片的数据,要保存到数据库中的时候,

            不可以直接使用insert语句对数据库进行操作,而是要使用ado的

            appendchunk方法,同样的,读出数据库中的图片数据,要使用getchunk方

            法。各个方法的具体语法如下:

            * request.binaryread语法:

            variant = request.binaryread(count)

            参数

            variant

            返回值保存着从客户端读取到数据。

            count

            指明要从客户端读取的数据量大小,这个值小于或者等于使用方法

            request.totalbytes得到的数据量。

            * request.binarywrite语法:

            request.binarywrite data

            参数

            data

            要写入到客户端浏览器中的数据包。

            * request.totalbytes语法:

            variant = request.totalbytes

            参数

            variant

            返回从客户端读取到数据量的字节数。

            * appendchunk语法

            将数据追加到大型文本、二进制数据 field 或 parameter 对象。

            object.appendchunk data

            参数

            object field 或 parameter 对象

            data 变体型,包含追加到对象中的数据。

            说明

            使用 field 或 parameter 对象的 appendchunk 方法可将长二进制或字符数

            据填写到对象中。在系统内存有限的情况下,可以使用 appendchunk 方法对长

            整型值进行部分而非全部的操作。

            * getchunk语法

            返回大型文本或二进制数据 field 对象的全部或部分内容 。

            variable = field.getchunk( size )

            返回值

            返回变体型。

            参数

            size 长整型表达式,等于所要检索的字节或字符数。

            说明

            使用 field 对象的 getchunk 方法检索其部分或全部长二进制或字符数据。

            在系统内存有限的情况下,可使用 getchunk 方法处理部分而非全部的长整型

            值。

            getchunk 调用返回的数据将赋给“变量”。如果 size 大于剩余的数据,则

            getchunk 仅返回剩余的数据而无需用空白填充“变量”。如果字段为空,则

            getchunk 方法返回 null。

            每个后续的 getchunk 调用将检索从前一次 getchunk 调用停止处开始的数

            据。但是,如果从一个字段检索数据然后在当前记录中设置或读取另一个字段

            的值,ado 将认为已从第一个字段中检索出数据。如果在第一个字段上再次调

            用 getchunk 方法,ado 将把调用解释为新的 getchunk 操作并从记录的起始

            处开始读取。如果其他 recordset 对象不是首个 recordset 对象的副本,则

            访问其中的字段不会破坏 getchunk 操作。

            如果 field 对象的 attributes 属性中的 adfldlong 位设置为 true,则可

            以对该字段使用 getchunk 方法。

            如果在 field 对象上使用 getchunk 方法时没有当前记录,将产生错误 3021

            (无当前记录)。

            接下来,我们就要来设计我们的数据库了,作为测试我们的数据库结构如

            下(access97):

            字段名称    类型    描述

              id    自动编号   主键值

            img ole对象   用来保存图片数据 



            对于在ms sql server7中,对应的结构如下:

            字段名称    类型    描述

              id     int(identity) 主键值

            img   image     用来保存图片数据 



            现在开始正式编写我们的纯asp代码上传部分了,首先,我们有一个提

            供给用户的上传界面,可以让用户选择要上传的图片。代码如下

            (upload.htm):

            <html>

            <body>

            <center>

               <form name="mainform" enctype="multipart/form-data"

            action="process.asp" method=post>

                <input type=file name=mefile><br>

               <input type=submit name=ok value="ok">

               </form>

            </center>

            </body>

            </html>

            注意代码中黑色斜体的部分,一定要在form中有这个属性,否则,将无

            法得到上传上来的数据。

            接下来,我们要在process.asp中对从浏览器中获取的数据进行必要的处

            理,因为我们在process.asp中获取到的数据不仅仅包含了我们想要的上传上来

            的图片的数据,也包含了其他的无用的信息,我们需要剔除冗余数据,并将处

            理过的图片数据保存到数据库中,这里我们以access97为例。具体代

            码如下(process.asp):

            <%

            response.buffer=true

            formsize=request.totalbytes

            formdata=request.binaryread(formsize)

            bncrlf=chrb(13) & chrb(10)

            divider=leftb(formdata,clng(instrb(formdata,bncrlf))-1)

            datastart=instrb(formdata,bncrlf & bncrlf)+4

            dataend=instrb(datastart+1,formdata,divider)-datastart

            mydata=midb(formdata,datastart,dataend)



            set conngraph=server.createobject("adodb.connection")

            conngraph.connectionstring="driver={microsoft access driver (*.mdb)};dbq=" &

            server.mappath("images.mdb") & ";uid=;pwd=;"

            conngraph.open



            set rec=server.createobject("adodb.recordset")

            rec.open "select * from [images] where id is null",conngraph,1,3

            rec.addnew

            rec("img").appendchunk mydata

            rec.update

            rec.close

            set rec=nothing

            set conngraph=nothing

            %>

            好了,这下我们就把上传来的图片保存到了名为images.mdb的数据库中

            了,剩下的工作就是要将数据库中的图片数据显示到网页上面了。一般在ht

            ml中,显示图片都是使用<img>标签,也就是<img src="图片路径">,但

            是我们的图片是保存到了数据库中,“图片路径”是什么呢?呵呵,其实这个

            src属性除了指定路径外,也可以这样使用哦:

            <img src="showimg.asp?id=xxx">

            所以,我们所要做的就是在showimg.asp中从数据库中读出来符合条件的

            数据,并返回到src属性中就可以了,具体代码如下(showimg.asp):

            <%

            set conngraph=server.createobject("adodb.connection")

            conngraph.connectionstring="driver={microsoft access driver (*.mdb)};dbq=" &

            server.mappath("images.mdb") & ";uid=;pwd=;"

            conngraph.open

            set rec=server.createobject("adodb.recordset")

            strsql="select img from images where id=" & trim(request("id"))

            rec.open strsql,conngraph,1,1

            response.contenttype = "image/*"

            response.binarywrite rec("img").getchunk(7500000)

            rec.close

            set rec=nothing

            set conngraph=nothing

            %>

            注意在输出到浏览器之前一定要指定response.contenttype = "image/*",

            以便正常显示图片。

            最后要注意的地方是,我的process.asp中作的处理没有考虑到第一页

            (upload.htm)中还有其他数据,比如<input type=tesxt name=userid>等等,如果

            有这些项目,你的process.asp就要注意处理掉不必要的数据。

            怎么样,其实上传图片并保存到数据库很简单吧,这样再也不用为自己的

            空间无法使用各类的上传组件发愁了吧。还等什么?赶快试一试吧。
            混杂的煙味.微熏的嘴.
            Powered by LeadBBS 9.2 .
            Page created in 0.2109 seconds with 4 queries.