maxpouliot
05-16-2006, 07:51 PM
How can i get the value of a field (in the code T1) when i upload a file (ENCTYPE="multipart/form-data") ?
<form method="post" ENCTYPE="multipart/form-data">
<input type="text" name="T1" size="20" value="1/213"><p>
<input type="file" name="file1" size="20"> <input type="submit" value="Ok">
</p>
</form>
Can't seem to find this info... i can't install components
miranda
05-16-2006, 08:05 PM
the upload components generally have a new collection available because you will no longer have access to the request.form collection. so try using something like I have below, just change the name of the object to reflect the upload component that you are using
Set upload = Server.CreateObject("Persits.Upload")
sText = upload.form("T1")
maxpouliot
05-16-2006, 08:10 PM
the upload components generally have a new collection available because you will no longer have access to the request.form collection. so try using something like I have below, just change the name of the object to reflect the upload component that you are using
Set upload = Server.CreateObject("Persits.Upload")
sText = upload.form("T1")
I get the following error
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/soutien_tache/outils/validations/uploadAsp.asp, line 112
anybody know why?
degsy
05-17-2006, 03:30 PM
so try using something like I have below, just change the name of the object to reflect the upload component that you are using
Did you change that or just copy the code?
Have you read the instructions for your upload component?
maxpouliot
05-17-2006, 04:27 PM
Did you change that or just copy the code?
Have you read the instructions for your upload component?
Did i change what? I can't use an upload component
degsy
05-18-2006, 04:31 PM
Why are you using Set upload = Server.CreateObject("Persits.Upload")
if you have no upload component?
You need to reference what ever you are using to upload the file
e.g.
http://forums.aspfree.com/code-bank-54/pure-asp-upload-script-with-additional-features-94647.html
objUpload.File(x).FileName
ghell
05-20-2006, 11:30 PM
the jacob gilley uploader in my sig is pureasp and will give you a nice way to work with both the file upload contents (on multiple files at once if you wish) and the normal form elements. the reason its in my sig is because its by far the best prewritten pure asp script i have seen for uploading. i also have a link to a tutorial about how to write your own (gives more depth into the complications of pure asp file upload). when you use a multipart encoded form you can no longer use Request.Form.
I always prefer using pure asp over COM Components :thumbsup:
maxpouliot
05-23-2006, 06:21 PM
Thanks Ghell, i use the updated faster version of jacob gilley uploader.
It's working with small files but when i choose a bigger file (>500 kb) i get the following error :
operation not allowed
Here's the code of the upload.asp file which comes with the updated version of jacob gilley uploader
<%
'***************************************
' File: Upload.asp
' Author: Jacob "Beezle" Gilley
' Email: avis7@airmail.net
' Date: 12/07/2000
' Comments: The code for the Upload, CByteString,
' CWideString subroutines was originally
' written by Philippe Collignon...or so
' he claims. Also, I am not responsible
' for any ill effects this script may
' cause and provide this script "AS IS".
' Enjoy!
'****************************************
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 = ""
If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(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)
For nIndex = 1 to LenB(FileData)
oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
Next
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
%>
ghell
05-24-2006, 12:42 PM
Hmm I'm not quite sure why it may error. I have been using the original script on a page on one of my sites for years and never had any problems. Asp i believe by default can only handle 40mB of data at once so i'm not sure. I also get timeout problems on large files if the server's download speed isnt that great.
I thought there was a way of restriricting filesize from this code but it may have been in the example of how to use the code or something. (I'm currently using the code to upload avatars to an old forum system I wrote a few years ago and I have a size constraint put on them but I may have just written that myself.)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.