• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

File Upload

fileupload.asp

<%

      call RequestBin()
      
      function RequestBin()

            Dim UploadControl,strName, Value
            set UploadControl = CreateObject("Scripting.Dictionary")  
            RequestBin = Request.BinaryRead(Request.TotalBytes)
            PosBegin = 1
            PosEnd = InStrB(1,RequestBin,getByte(chr(13)))

            If PosEnd > 0 then
                  boundary = MidB(RequestBin,PosBegin,PosEnd-PosBegin)
                  boundaryPos = MidB(PosBegin,RequestBin,boundary)
            End If  

                If boundary <> 0 then

                        PosEnd = InStrB(PosBegin,RequestBin,getByte(chr("&")))
                       
                        Do While PosBegin < LenB(RequestBin)                        
                            Temp = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))
                            tempPos = InStr(PosBegin,Temp,"=")
                            Name = URLDecode(Left(Temp,tempPos-PosBegin))
                            Value = URLDecode(Right(Temp,Len(Temp)-tempPos))
                            uploadControl.add Name,Value
                            PosBegin = PosEnd + 1    
                            PosEnd = InStrB(PosBegin,RequestBin,getByte(chr("&")))
                            If PosEnd = 0 then PosEnd = LenB(RequestBin) + 1                      
                        Loop
                        Else
                        Do Until(boundaryPos=InStrB(RequestBin,boundary & getByte("--")))  
                            set UploadControl = CreateObject("Scripting.Dictionary")
                            Pos = InStrB(boundaryPos,RequestBin,getByte("Content-Disposition"))
                            Pos = InStrB(Pos,RequestBin,getByte("name="))
                            PosBegin = Pos + 6
                            PosEnd = InStrB(PosBegin,RequestBin,getByte(chr(34)))
                            Name = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))
                            Pos = InStrB(boundaryPos,RequestBin,getByte("filename="))
                            boundaryPos = MidB(PosBegin,RequestBin,boundary)
                            If Pos <> 0 AND (Pos<boundaryPos) Then
                                  PosBegin = Pos + 10
                                PosEnd = InStrB(PosBegin,RequestBin,getByte(chr(34)))  
                                FileName = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))
                                UploadControl.Add strName, FileName
                                Pos = InStrB(boundaryPos,RequestBin,getByte("Content-Type:"))
                                PosBegin = Pos + 14  
                                PosEnd = InStrB(PosBegin,RequestBin,getByte(chr(13)))
                                ContentType = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))  
                                UploadControl.Add strName,ContentType
                                                PosBegin = Pos + 4    
                                PosEnd = InStrB(PosBegin,RequestBin,boundaryPos) - 2
                                Value = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))
                            Else
                                                UploadControl.Add strName,Value            
                                                boundaryPos=InstrB(boundaryPos+LenB(boundary),RequestBin,boundary)
                                          End If                                                                                                                
                        Loop                      
                End if

                        Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
                        Set MyFile = ScriptObject.CreateTextFile(Server.mappath("db/" & FileName))

      End function

      function URLDecode(sText)

              sDecoded = sText
              Set oRegExpr = Server.CreateObject("VBScript.RegExp")
              oRegExpr.Pattern = "%[0-9,A-F]{2}"
              oRegExpr.Global = True
              Set oMatchCollection = oRegExpr.Execute(sText)
              For Each oMatch In oMatchCollection
                 sDecoded = Replace(sDecoded,oMatch.value,Chr(CInt("&H" & Right(oMatch.Value,2))))
              Next
              URLDecode = sDecoded
              
      End function
      
      Function getString(StringBin)
 
              getString =""
              For intCount = 1 to LenB(StringBin)
                getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
              Next
              
      End Function

      Function getByte(ByteBin)
 
              getByte =""
              For intCount = 1 to Len(ByteBin)
                getByte = getByte & chrB(AscB(MidB(ByteBin,intCount,1)))
              Next

      End Function

%>


upload.html

<HTML>
  <HEAD>
</HEAD>
<BODY>
  <form METHOD='Post' ENCTYPE='multipart/form-data' ACTION='fileupload.asp'>
    <input TYPE="file" NAME="blob" class="input" size="20">
    <input type='submit' name='Action' value='UPLOAD'>
  </form>
</body>
</html>


I tried uploading an image but it takes me to page not found. No image is being uploaded. How do I solve this problem. Your help is kindly appreciated.
0
eugene007
Asked:
eugene007
1 Solution
 
RainMan82Commented:
I've used PureASP from

http://www.pstruh.cz/help/ScptUtl/library.htm

It is free, does not need components, comes with a working example, and even a novice like myself can edit it to work the way I want it to.
0
 
kevp75Commented:
you actually aren't doing anything other than calling RequestBin().  It looks like you need to pass variables to it in order for it to do the processing.

Do you have a link to where you got this script from?
0
 
eugene007Author Commented:
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kevp75Commented:
ok.  Like I said, you aren't doing any processing on your fileupload.asp page

see the first link you posted:
<%
Dim objUpload, lngLoop

If Request.TotalBytes > 0 Then
      Set objUpload = New vbsUpload

  For lngLoop = 0 to objUpload.Files.Count - 1
    'If accessing this page annonymously,
    'the internet guest account must have
    'write permission to the path below.
    objUpload.Files.Item(lngLoop).Save "c:\Newupload\"

      Response.Write "File Uploaded"
      Next

End if
%>


The code you have posted for it is the uploader class itself.....
0
 
eugene007Author Commented:
now in my upload.asp file I did the following:

<!-- #include file="fileUpload.asp" -->

<HTML>
  <HEAD>
</HEAD>
<BODY>
  <form METHOD='Post' ENCTYPE='multipart/form-data' ACTION='upload.asp'>
    <input TYPE="file" NAME="blob" class="input" size="20">
    <input type='submit' name='Action' value='UPLOAD'>
  </form>
</body>
</html>

and when I attemp to upload a file and check my web server db folder, I see a file name db, 0 kb in size.
0
 
kevp75Commented:
upload.asp should be this:
<!-- #include file="fileUpload.asp" -->
<%
Dim objUpload, lngLoop

If Request.TotalBytes > 0 Then
     Set objUpload = New vbsUpload

  For lngLoop = 0 to objUpload.Files.Count - 1
    'If accessing this page annonymously,
    'the internet guest account must have
    'write permission to the path below.
    objUpload.Files.Item(lngLoop).Save "c:\Newupload\"

     Response.Write "File Uploaded"
     Next

End if
%>

and you can get rid of the <!-- #include file="fileUpload.asp" --> on your form page
0
 
eugene007Author Commented:
I came up with the fileupload.asp file a little different than the one shown on the website as in:

<SCRIPT LANGUAGE=vbscript RUNAT=Server>
Class vbsUpload

      Private Sub Class_Initialize()
            call RequestBin()
      End Sub

      function RequestBin()

            Dim UploadControl,strName, Value, RequestBin
            Dim PosBegin, PosEnd
            set UploadControl = CreateObject("Scripting.Dictionary")  
            RequestBin = Request.BinaryRead(Request.TotalBytes)
            PosBegin = 1
            PosEnd = InStrB(1,RequestBin,getByte(chr(13)))

            If PosEnd > 0 then
                  boundary = MidB(RequestBin,PosBegin,PosEnd-PosBegin)
                  boundaryPos = InStrB(PosBegin,RequestBin,boundary)
            End If  

                If boundary = "" then

                        PosEnd = InStrB(PosBegin,RequestBin,getByte(chr("&")))
                       
                        Do While PosBegin < LenB(RequestBin)                        
                            Temp = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))
                            tempPos = InStr(PosBegin,Temp,"=")
                            Name = URLDecode(Left(Temp,tempPos-PosBegin))
                            Value = URLDecode(Right(Temp,Len(Temp)-tempPos))
                            uploadControl.add Name,Value
                            PosBegin = PosEnd + 1    
                            PosEnd = InStrB(PosBegin,RequestBin,getByte(chr("&")))
                            If PosEnd = 0 then PosEnd = LenB(RequestBin) + 1                      
                        Loop
                        Else
                        Do Until(boundaryPos=InStrB(RequestBin,boundary & getByte("--")))  
                            set UploadControl = CreateObject("Scripting.Dictionary")
                            Pos = InStrB(boundaryPos,RequestBin,getByte("Content-Disposition"))
                            Pos = InStrB(Pos,RequestBin,getByte("name="))
                            PosBegin = Pos + 6
                            PosEnd = InStrB(PosBegin,RequestBin,getByte(chr(34)))
                            Name = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))
                            Pos = InStrB(boundaryPos,RequestBin,getByte("filename="))
                            boundaryPos = MidB(PosBegin,RequestBin,boundary)
                            If Pos <> 0 AND (Pos<boundaryPos) Then
                                  PosBegin = Pos + 10
                                PosEnd = InStrB(PosBegin,RequestBin,getByte(chr(34)))  
                                FileName = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))
                                UploadControl.Add strName, FileName
                                Pos = InStrB(boundaryPos,RequestBin,getByte("Content-Type:"))
                                PosBegin = Pos + 14  
                                PosEnd = InStrB(PosBegin,RequestBin,getByte(chr(13)))
                                ContentType = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))  
                                UploadControl.Add strName,ContentType
                                                PosBegin = Pos + 4    
                                PosEnd = InStrB(PosBegin,RequestBin,boundaryPos) - 2
                                Value = getString(MidB(RequestBin,PosBegin,PosEnd-PosBegin))
                            Else
                                                UploadControl.Add strName,Value            
                                                boundaryPos=InstrB(boundaryPos+LenB(boundary),RequestBin,boundary)
                                          End If                                                                                                                
                        Loop                      
                End if
               
      End function

      function URLDecode(sText)

              sDecoded = sText
              Set oRegExpr = Server.CreateObject("VBScript.RegExp")
              oRegExpr.Pattern = "%[0-9,A-F]{2}"
              oRegExpr.Global = True
              Set oMatchCollection = oRegExpr.Execute(sText)
              For Each oMatch In oMatchCollection
                 sDecoded = Replace(sDecoded,oMatch.value,Chr(CInt("&H" & Right(oMatch.Value,2))))
              Next
              URLDecode = sDecoded
              
      End function
      
      Function getString(StringBin)
 
              getString =""
              For intCount = 1 to LenB(StringBin)
                getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
              Next
              
      End Function

      Function getByte(ByteBin)
 
              getByte =""
              For intCount = 1 to Len(ByteBin)
                getByte = getByte & chrB(AscB(MidB(ByteBin,intCount,1)))
              Next

      End Function
      
End Class
</SCRIPT>


so using:

upload.asp should be this:
<!-- #include file="fileUpload.asp" -->
<%
Dim objUpload, lngLoop

If Request.TotalBytes > 0 Then
     Set objUpload = New vbsUpload

  For lngLoop = 0 to objUpload.Files.Count - 1
    'If accessing this page annonymously,
    'the internet guest account must have
    'write permission to the path below.
    objUpload.Files.Item(lngLoop).Save "c:\Newupload\"

     Response.Write "File Uploaded"
     Next

End if
%>


does not seem to work.
0
 
kevp75Commented:
ok, it looks like what you have done is converted it to VBA (visual basic for applications)

your best bet would be to use the original code that you downloaded, and use it exactly how they show to use it
0
 
kevp75Commented:
i don't really have any objections, but I would liked to have known the outcome
0
 
GranModCommented:
Closed, 80 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now