problems with upload file.

This is a discussion on "problems with upload file." within the Classic ASP section. This forum, and the thread "problems with upload file. are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Dec 11th, 2005, 17:52
Junior Member
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
problems with upload file.

I found this script to upload a file with ASP:
http://www.asp101.com/articles/jacob/scriptupload.asp

I'm uploading a file and setting values from a form to a SQL database.

It tells me:
Request object error 'ASP 0206 : 80004005'
Cannot call BinaryRead
/secur-it/upload.asp, line 64
Cannot call BinaryRead after using Request.Form collection.


So I went to the upload.asp file thats included and commented out this line:
Line 64: biData = Request.BinaryRead(Request.TotalBytes)


That fixed the error, but then it won't get the file name, or save it to the folder on the server.

how do I do a form request AND upload a file?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 12th, 2005, 20:25
Junior Member
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: problems with upload file.

OK so I've found out that you can't submit form data and upload a file at the same time, but the code in the included upload.asp file has code to get the data from the fields in a form:

Code: Select all
Public Property Get Form(sIndex)
Form = ""
Form = mcolFormElem.Item(sIndex)
End Property
But for some reason every time I hit "submit" that code returns a value of "" and not the text that was entered..

here is my code doing that:

Code: Select all
Dim myUploader
Set myUploader = New FileUploader
 
if myUploader.Form("txtFirst")<>"" then rsReq("firstname")=myUploader.Form("txtFirst")
if myUploader.Form("txtMiddle")<>"" then rsReq("middlename")=myUploader.Form("txtMiddle")
if myUploader.Form("txtLast")<>"" then rsReq("lastname")=myUploader.Form("txtLast")
anyone know why it's not returning the values?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Dec 13th, 2005, 12:51
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
Re: problems with upload file.

Please post your ENTIRE code so we can help you.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Dec 13th, 2005, 15:01
Junior Member
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: problems with upload file.

its a lot, but here ya go:
upload.asp:
Code: Select all
<!--#include file="buffering.inc"-->
<%
Class FileUploader
Public Files
Private mcolFormElem
Private Sub Class_Initialize()
Set Files = Server.CreateObject("Scripting.Dictionary")
Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
End Sub 
Private Sub Class_Terminate()
If IsObject(Files) Then
Files.RemoveAll()
Set Files = Nothing
End If
If IsObject(mcolFormElem) Then
mcolFormElem.RemoveAll()
Set mcolFormElem = Nothing
End If
End Sub
Public Property Get Form(sIndex)
Form = ""
Form = mcolFormElem.Item(sIndex)
End Property
Public Default Sub Upload()
Dim biData, sInputName
Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
Dim nPosFile, nPosBound
biData = Request.BinaryRead(Request.TotalBytes)
nPosBegin = 1
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13))) 
If (nPosEnd-nPosBegin) <= 0 Then Exit Sub 
vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
nDataBoundPos = InstrB(1, biData, vDataBounds) 
Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
nPos = InstrB(nPos, biData, CByteString("name="))
nPosBegin = nPos + 6
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
nPosBound = InstrB(nPosEnd, biData, vDataBounds) 
If nPosFile <> 0 And nPosFile < nPosBound Then
Dim oUploadFile, sFileName
Set oUploadFile = New UploadedFile 
nPosBegin = nPosFile + 10
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))
nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
nPosBegin = nPos + 14
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13))) 
oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
nPosBegin = nPosEnd+4
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin) 
If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
Else
nPos = InstrB(nPos, biData, CByteString(Chr(13)))
nPosBegin = nPos + 4
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
End If
nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
Loop
End Sub
'String to byte string conversion
Private Function CByteString(sString)
Dim nIndex
For nIndex = 1 to Len(sString)
CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
Next
End Function
'Byte string to string conversion
Private Function CWideString(bsString)
Dim nIndex
CWideString =""
For nIndex = 1 to LenB(bsString)
CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1))) 
Next
End Function
End Class
Class UploadedFile
Public ContentType
Public FileName
Public FileData
Public Property Get FileSize()
FileSize = LenB(FileData)
End Property
Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex 
If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\" 
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub 
Set oFile = oFS.CreateTextFile(sPath & FileName, True)
' output mechanism modified for buffering
oFile.Write BufferContent(FileData)
oFile.Close
End Sub 
Public Sub SaveToDatabase(ByRef oField)
If LenB(FileData) = 0 Then Exit Sub 
If IsObject(oField) Then
oField.AppendChunk FileData
End If
End Sub
End Class
%>
bufferinc.inc:
Code: Select all
<%
' Original Code written by: Robbert Nix
' Adapted and Modified by: Will Bickford
' Date: 12/20/2002
' Email: wbic16@hotmail.com
' From: http://www.planet-source-code.com/vb...txtCodeId=7110
Function BufferContent(data)
Dim strContent(64)
Dim i
ClearString strContent
For i = 1 To LenB(data)
AddString strContent,Chr(AscB(MidB(data,i,1)))
Next
BufferContent = fnReadString(strContent)
End Function
Sub ClearString(part)
Dim index
For index = 0 to 64
part(index)=""
Next
End Sub
Sub AddString(part,newString)
Dim tmp
Dim index
part(0) = part(0) & newString
If Len(part(0)) > 64 Then
index=0
tmp=""
Do
tmp=part(index) & tmp
part(index) = ""
index = index + 1
Loop until part(index) = ""
part(index) = tmp
End If
End Sub
Function fnReadString(part)
Dim tmp
Dim index
tmp = ""
For index = 0 to 64
If part(index) <> "" Then
tmp = part(index) & tmp
End If
Next
FnReadString = tmp
End Function
%>
and the submitorder.asp that is supposed to upload the file:
Code: Select all
<<A href="mailto:%@LANGUAGE="VBSCRIPT">%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!-- #include file="inc/dbconn.inc"-->
<!-- #include file="inc/upload.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Submit Order</title>
</head>
<body>
<%
Dim myUploader
Set myUploader = New FileUploader
sqlStr = "SELECT * FROM tblRequests"
Set rsReq = Server.CreateObject("ADODB.Recordset")
rsReq.open sqlStr,dbConn,2,3 
'Below are standard for ever record
rsReq.addnew
rsReq("clientID")=Session("userID")
rsReq("checktype")=Session("CheckType")
rsReq("dateEntered")=FormatDateTime(now(),2)
rsReq("status")="Submitted"
'Check to see whats in the Forms and add it
if myUploader.Form("txtFirst")<>"" then rsReq("firstname")=myUploader.Form("txtFirst")
if myUploader.Form("txtMiddle")<>"" then rsReq("middlename")=myUploader.Form("txtMiddle")
if myUploader.Form("txtLast")<>"" then rsReq("lastname")=myUploader.Form("txtLast")
if myUploader.Form("txtDLNum")<>"" then rsReq("driverslicense")=myUploader.Form("txtDLNum")
if myUploader.Form("txtDOB")<>"" then rsReq("dob")=myUploader.Form("txtDOB")
if myUploader.Form("txtGender")<>"" then rsReq("gender")=myUploader.Form("txtGender")
if myUploader.Form("txtAddress")<>"" then rsReq("address")=myUploader.Form("txtAddress")
if myUploader.Form("txtCity")<>"" then rsReq("city")=myUploader.Form("txtCity")
if myUploader.Form("txtState")<>"" then rsReq("state")=myUploader.Form("txtState")
if myUploader.Form("txtZipCode")<>"" then rsReq("zipcode")=myUploader.Form("txtZipCode")
if myUploader.Form("authorizationFile")<>"" then
'Authorization File
myUploader.Upload()
Dim File
For Each File in myUploader.Files.Items
fileName = File.FileName
File.SaveToDisk "authorizations\"
Next 
rsReq("signedauthorization")=fileName
end if
rsReq.update
rsReq.movelast
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Dec 13th, 2005, 15:26
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,189
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
Re: problems with upload file.

Are you using multipart/form-data as your form enctype?
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Dec 13th, 2005, 17:33
Junior Member
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: problems with upload file.

Quote:
Originally Posted by Rob
Are you using multipart/form-data as your form enctype?
Tried that didn't seem to work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
problems, upload, file

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP+SQL+File Upload joshlindem PHP Forum 5 May 10th, 2008 16:48
file upload berry05 Job Opportunities 0 Mar 19th, 2008 19:09
File Upload magiccupcake PHP Forum 1 Jan 22nd, 2007 05:10
File upload djme PHP Forum 4 Jan 11th, 2006 18:25
asp file upload script having problems with MYSQL paulmcn Classic ASP 2 Oct 5th, 2005 18:45


All times are GMT. The time now is 06:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42