Upload File

Results 1 to 2 of 2

Thread: Upload File

  1. #1
    Join Date
    Dec 1969

    Default Upload File

    I am using VBScript class to upload file from a web page the code for the class is as follows:<BR><BR>&#060;%<BR>&#039;Created By: Shweta Singh<BR>&#039;Dated:18 September,2002<BR>&#039;Purpose:Provides functionality to upload files through a web page from users machine to the web server<BR><BR>Class FileUploader<BR> Public Files<BR> Private mcolFormElem<BR><BR> Private Sub Class_Initialize()<BR> Set Files = Server.CreateObject("Scripting.Dictionary")<BR> Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")<BR> End Sub<BR> <BR> Private Sub Class_Terminate()<BR> If IsObject(Files) Then<BR> Files.RemoveAll()<BR> Set Files = Nothing<BR> End If<BR> If IsObject(mcolFormElem) Then<BR> mcolFormElem.RemoveAll()<BR> Set mcolFormElem = Nothing<BR> End If<BR> End Sub<BR><BR> Public Property Get Form(sIndex)<BR> Form = ""<BR> If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))<BR> End Property<BR><BR> Public Default Sub Upload()<BR> Dim biData, sInputName<BR> Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos<BR> Dim nPosFile, nPosBound<BR><BR> biData = Request.BinaryRead(Request.TotalBytes)<BR> nPosBegin = 1<BR> nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))<BR> <BR> If (nPosEnd-nPosBegin) &#060;= 0 Then Exit Sub<BR> <BR> vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)<BR> nDataBoundPos = InstrB(1, biData, vDataBounds)<BR> <BR> Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))<BR> <BR> nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))<BR> nPos = InstrB(nPos, biData, CByteString("name="))<BR> nPosBegin = nPos + 6<BR> nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))<BR> sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))<BR> nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))<BR> nPosBound = InstrB(nPosEnd, biData, vDataBounds)<BR> <BR> If nPosFile &#060;&#062; 0 And nPosFile &#060; nPosBound Then<BR> Dim oUploadFile, sFileName<BR> Set oUploadFile = New UploadedFile<BR> <BR> nPosBegin = nPosFile + 10<BR> nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))<BR> sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))<BR> oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))<BR><BR> nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))<BR> nPosBegin = nPos + 14<BR> nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))<BR> <BR> oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))<BR> <BR> nPosBegin = nPosEnd+4<BR> nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2<BR> oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)<BR> <BR> If oUploadFile.FileSize &#062; 0 Then Files.Add LCase(sInputName), oUploadFile<BR> Else<BR> nPos = InstrB(nPos, biData, CByteString(Chr(13)))<BR> nPosBegin = nPos + 4<BR> nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2<BR> If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))<BR> End If<BR><BR> nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)<BR> Loop<BR> End Sub<BR><BR> &#039;String to byte string conversion<BR> Private Function CByteString(sString)<BR> Dim nIndex<BR> For nIndex = 1 to Len(sString)<BR> CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))<BR> Next<BR> End Function<BR><BR> &#039;Byte string to string conversion<BR> Private Function CWideString(bsString)<BR> Dim nIndex<BR> CWideString =""<BR> For nIndex = 1 to LenB(bsString)<BR> CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1))) <BR> Next<BR> End Function<BR>End Class<BR><BR>Class UploadedFile<BR> Public ContentType<BR> Public FileName<BR> Public FileData<BR> <BR> Public Property Get FileSize()<BR> FileSize = LenB(FileData)<BR> End Property<BR><BR> Public Sub SaveToDisk(sPath)<BR> Dim oFS, oFile<BR> Dim nIndex<BR> <BR> If sPath = "" Or FileName = "" Then Exit Sub<BR> If Mid(sPath, Len(sPath)) &#060;&#062; "\" Then sPath = sPath & "\"<BR> <BR> Set oFS = Server.CreateObject("Scripting.FileSystemObject")< BR> If Not oFS.FolderExists(sPath) Then Exit Sub<BR> <BR> Set oFile = oFS.CreateTextFile(sPath & FileName, True)<BR> <BR> For nIndex = 1 to LenB(FileData)<BR> oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))<BR> Next<BR><BR> oFile.Close<BR> End Sub<BR> <BR> Public Sub SaveToDatabase(ByRef oField)<BR> If LenB(FileData) = 0 Then Exit Sub<BR> <BR> If IsObject(oField) Then<BR> oField.AppendChunk FileData<BR> End If<BR> End Sub<BR><BR>End Class<BR>%&#062;<BR><BR><BR>My problem is that this code works fine on my testing server however in the clients server it is giving the following error:Microsoft VBScript compilation error &#039;800a0401&#039; <BR><BR>Expected end of statement <BR><BR>/catdemo02/FileUploadClass.asp, line 26 <BR><BR>Public Property Get Form(sIndex)<BR>----------------^<BR><BR><BR>The way i am accessing the class in my asp file is as follows. I have included the class file at the top of the page:<BR><BR>&#039; Creating the FileUploader using class FileUploaded in FileUploadClass.asp <BR>Dim Uploader, File<BR>Set Uploader = New FileUploader<BR><BR>&#039; This starts the upload process by caling the upload method of the fileuploader class<BR>Uploader.Upload()<BR><BR><BR>If Uploader.Files.Count = 0 Then<BR>&#039;Do Nothing<BR>Else<BR>&#039; Loop through the uploaded files<BR> For Each File In Uploader.Files.Items<BR> File.SaveToDisk "D:inetpubwwwrootVodaGlobalUploadFiles\"<BR> strScreenShotImages = File.FileName<BR> Next<BR>End If<BR><BR>*********************<BR><BR>PLEASE HELP IT IS VERY URGENT!!!<BR><BR>THANKS IN ADVANCE <BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Upload File

    check the script engine versions on your server and the client , off the top of my head i thought it vas version 5.6 that allows classes to be coded (could be wrong though !!!)<BR>jon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts