Results 1 to 4 of 4


  1. #1
    Ashraf Alsadiq Guest


    I need to upload ms doc/xls file from client to server.! Any one can help me get started using asp to do this?<BR>I tried to upload ascii files its okay. But when uploading other than that I failed what is wrong. Any body can help me please.<BR><BR>Thanks in advance.

  2. #2
    Join Date
    Dec 1969

    Default RE:

    do you have an upload component installed on the server?<BR><BR>j

  3. #3
    Ashraf Alsadiq Guest

    Default RE:

    No, I did it thru VB script file object.

  4. #4
    Ali Guest

    Default RE:

    You can upload without component too, <BR><BR>Here is.... solution. just copy this follosing and paste as file upload.asp and save it. and second part is in second part as test.asp . <BR>So you will have two files one is upload.asp and second is test.asp .... just run test.asp ..... and Enjoy! have fun!<BR><BR>Ali<BR><BR><BR>****** ******************<BR>Part one save as upload.asp<BR>************************<BR><BR>&#06 0;SCRIPT LANGUAGE=vbscript RUNAT=Server&#062;<BR>Class clsUpload<BR>&#039================================ =========================&#039<BR>&#039 This class will parse the binary contents of the &#039<BR>&#039 request, and populate the Form and Files collections. &#039<BR>&#039==================================== =====================&#039<BR> Private m_objFiles<BR> Private m_objForm<BR> <BR> Public Property Get Form()<BR> Set Form = m_objForm<BR> End Property<BR> <BR> Public Property Get Files()<BR> Set Files = m_objFiles<BR> End Property<BR> <BR> Private Sub Class_Initialize()<BR> Set m_objFiles = New clsCollection<BR> Set m_objForm = New clsCollection<BR> ParseRequest<BR> End Sub<BR> <BR> Private Sub ParseRequest()<BR> Dim lngTotalBytes, lngPosBeg, lngPosEnd, lngPosBoundary, lngPosTmp, lngPosFileName<BR> Dim strBRequest, strBBoundary, strBContent<BR> Dim strName, strFileName, strContentType, strValue, strTemp<BR> Dim objFile<BR> <BR> &#039Grab the entire contents of the Request as a Byte string<BR> lngTotalBytes = Request.TotalBytes<BR> strBRequest = Request.BinaryRead(lngTotalBytes)<BR> <BR> &#039Find the first Boundary<BR> lngPosBeg = 1<BR> lngPosEnd = InStrB(lngPosBeg, strBRequest, UStr2Bstr(Chr(13)))<BR> If lngPosEnd &#062; 0 Then<BR> strBBoundary = MidB(strBRequest, lngPosBeg, lngPosEnd - lngPosBeg)<BR> lngPosBoundary = InStrB(1, strBRequest, strBBoundary)<BR> End If<BR> If strBBoundary = "" Then<BR> &#039The form must have been submitted *without* ENCTYPE="multipart/form-data"<BR> &#039But since we already called Request.BinaryRead, we can no longer access<BR> &#039the Request.Form collection, so we need to parse the request and populate<BR> &#039our own form collection.<BR> lngPosBeg = 1<BR> lngPosEnd = InStrB(lngPosBeg, strBRequest, UStr2BStr("&"))<BR> Do While lngPosBeg &#060; LenB(strBRequest)<BR> &#039Parse the element and add it to the collection<BR> strTemp = BStr2UStr(MidB(strBRequest, lngPosBeg, lngPosEnd - lngPosBeg))<BR> lngPosTmp = InStr(1, strTemp, "=")<BR> strName = URLDecode(Left(strTemp, lngPosTmp - 1))<BR> strValue = URLDecode(Right(strTemp, Len(strTemp) - lngPosTmp))<BR> m_objForm.Add strName, strValue<BR> &#039Find the next element<BR> lngPosBeg = lngPosEnd + 1<BR> lngPosEnd = InStrB(lngPosBeg, strBRequest, UStr2BStr("&"))<BR> If lngPosEnd = 0 Then lngPosEnd = LenB(strBRequest) + 1<BR> Loop<BR> Else<BR> &#039The form was submitted with ENCTYPE="multipart/form-data"<BR> &#039Loop through all the boundaries, and parse them into either the<BR> &#039Form or Files collections.<BR> Do Until (lngPosBoundary = InStrB(strBRequest, strBBoundary & UStr2Bstr("--")))<BR> &#039Get the element name<BR> lngPosTmp = InStrB(lngPosBoundary, strBRequest, UStr2BStr("Content-Disposition"))<BR> lngPosTmp = InStrB(lngPosTmp, strBRequest, UStr2BStr("name="))<BR> lngPosBeg = lngPosTmp + 6<BR> lngPosEnd = InStrB(lngPosBeg, strBRequest, UStr2BStr(Chr(34)))<BR> strName = BStr2UStr(MidB(strBRequest, lngPosBeg, lngPosEnd - lngPosBeg))<BR> &#039Look for an element named &#039filename&#039<BR> lngPosFileName = InStrB(lngPosBoundary, strBRequest, UStr2BStr("filename="))<BR> &#039If found, we have a file, otherwise it is a normal form element<BR> If lngPosFileName &#060;&#062; 0 And lngPosFileName &#060; InStrB(lngPosEnd, strBRequest, strBBoundary) Then &#039It is a file<BR> &#039Get the FileName<BR> lngPosBeg = lngPosFileName + 10<BR> lngPosEnd = InStrB(lngPosBeg, strBRequest, UStr2BStr(chr(34)))<BR> strFileName = BStr2UStr(MidB(strBRequest, lngPosBeg, lngPosEnd - lngPosBeg))<BR> &#039Get the ContentType<BR> lngPosTmp = InStrB(lngPosEnd, strBRequest, UStr2BStr("Content-Type:"))<BR> lngPosBeg = lngPosTmp + 14<BR> lngPosEnd = InstrB(lngPosBeg, strBRequest, UStr2BStr(chr(13)))<BR> strContentType = BStr2UStr(MidB(strBRequest, lngPosBeg, lngPosEnd - lngPosBeg))<BR> &#039Get the Content<BR> lngPosBeg = lngPosEnd + 4<BR> lngPosEnd = InStrB(lngPosBeg, strBRequest, strBBoundary) - 2<BR> strBContent = MidB(strBRequest, lngPosBeg, lngPosEnd - lngPosBeg)<BR> If strFileName &#060;&#062; "" And strBContent &#060;&#062; "" Then<BR> &#039Create the File object, and add it to the Files collection<BR> Set objFile = New clsFile<BR> objFile.Name = strName<BR> objFile.FileName = Right(strFileName, Len(strFileName) - InStrRev(strFileName, "\"))<BR> objFile.ContentType = strContentType<BR> objFile.Blob = strBContent<BR> m_objFiles.Add strName, objFile<BR> End If<BR> Else &#039It is a form element<BR> &#039Get the value of the form element<BR> lngPosTmp = InStrB(lngPosTmp, strBRequest, UStr2BStr(chr(13)))<BR> lngPosBeg = lngPosTmp + 4<BR> lngPosEnd = InStrB(lngPosBeg, strBRequest, strBBoundary) - 2<BR> strValue = BStr2UStr(MidB(strBRequest, lngPosBeg, lngPosEnd - lngPosBeg))<BR> &#039Add the element to the collection<BR> m_objForm.Add strName, strValue<BR> End If<BR> &#039Move to Next Element<BR> lngPosBoundary = InStrB(lngPosBoundary + LenB(strBBoundary), strBRequest, strBBoundary)<BR> Loop<BR> End If<BR> End Sub<BR> <BR> Private Function BStr2UStr(BStr)<BR> &#039Byte string to Unicode string conversion<BR> Dim lngLoop<BR> BStr2UStr = ""<BR> For lngLoop = 1 to LenB(BStr)<BR> BStr2UStr = BStr2UStr & Chr(AscB(MidB(BStr,lngLoop,1))) <BR> Next<BR> End Function<BR> <BR> Private Function UStr2Bstr(UStr)<BR> &#039Unicode string to Byte string conversion<BR> Dim lngLoop<BR> Dim strChar<BR> UStr2Bstr = ""<BR> For lngLoop = 1 to Len(UStr)<BR> strChar = Mid(UStr, lngLoop, 1)<BR> UStr2Bstr = UStr2Bstr & ChrB(AscB(strChar))<BR> Next<BR> End Function<BR> <BR> Private Function URLDecode(Expression)<BR> &#039Why doesn&#039t ASP provide this functionality for us?<BR> Dim strSource, strTemp, strResult<BR> Dim lngPos<BR> strSource = Replace(Expression, "+", " ")<BR> For lngPos = 1 To Len(strSource)<BR> strTemp = Mid(strSource, lngPos, 1)<BR> If strTemp = "%" Then<BR> If lngPos + 2 &#060; Len(strSource) Then<BR> strResult = strResult & Chr(CInt("&H" & Mid(strSource, lngPos + 1, 2)))<BR> lngPos = lngPos + 2<BR> End If<BR> Else<BR> strResult = strResult & strTemp<BR> End If<BR> Next<BR> URLDecode = strResult<BR> End Function <BR> <BR>End Class<BR><BR>Class clsCollection<BR>&#039============================ =============================&#039<BR>&#039 This class is a pseudo-collection. It is not a real &#039<BR>&#039 collection, because there is no way that I am aware &#039<BR>&#039 of to implement an enumerator to support the &#039<BR>&#039 For..Each syntax using VBScript classes. &#039<BR>&#039==================================== =====================&#039<BR> Private m_objDicItems<BR> <BR> Private Sub Class_Initialize()<BR> Set m_objDicItems = Server.CreateObject("Scripting.Dictionary")<BR> m_objDicItems.CompareMode = vbTextCompare<BR> End Sub<BR> <BR> Public Property Get Count()<BR> Count = m_objDicItems.Count<BR> End Property<BR> <BR> Public Default Function Item(Index)<BR> Dim arrItems<BR> If IsNumeric(Index) Then<BR> arrItems = m_objDicItems.Items<BR> If IsObject(arrItems(Index)) Then<BR> Set Item = arrItems(Index)<BR> Else<BR> Item = arrItems(Index)<BR> End If<BR> Else<BR> If m_objDicItems.Exists(Index) Then<BR> If IsObject(m_objDicItems.Item(Index)) Then<BR> Set Item = m_objDicItems.Item(Index)<BR> Else<BR> Item = m_objDicItems.Item(Index)<BR> End If<BR> End If<BR> End If<BR> End Function<BR> <BR> Public Function Key(Index)<BR> Dim arrKeys<BR> If IsNumeric(Index) Then<BR> arrKeys = m_objDicItems.Keys<BR> Key = arrKeys(Index)<BR> End If<BR> End Function<BR> <BR> Public Sub Add(Name, Value)<BR> If m_objDicItems.Exists(Name) Then<BR> m_objDicItems.Item(Name) = Value<BR> Else<BR> m_objDicItems.Add Name, Value<BR> End If<BR> End Sub<BR>End Class<BR><BR>Class clsFile<BR>&#039================================== =======================&#039<BR>&#039 This class is used as a container for a file sent via &#039<BR>&#039 an http multipart/form-data post. &#039<BR>&#039==================================== =====================&#039<BR> Private m_strName<BR> Private m_strContentType<BR> Private m_strFileName<BR> Private m_Blob<BR> <BR> Public Property Get Name() : Name = m_strName : End Property<BR> Public Property Let Name(vIn) : m_strName = vIn : End Property<BR> Public Property Get ContentType() : ContentType = m_strContentType : End Property<BR> Public Property Let ContentType(vIn) : m_strContentType = vIn : End Property<BR> Public Property Get FileName() : FileName = m_strFileName : End Property<BR> Public Property Let FileName(vIn) : m_strFileName = vIn : End Property<BR> Public Property Get Blob() : Blob = m_Blob : End Property<BR> Public Property Let Blob(vIn) : m_Blob = vIn : End Property<BR><BR> Public Sub Save(Path)<BR> Dim objFSO, objFSOFile<BR> Dim lngLoop<BR> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")< BR> Set objFSOFile = objFSO.CreateTextFile(objFSO.BuildPath(Path, m_strFileName))<BR> For lngLoop = 1 to LenB(m_Blob)<BR> objFSOFile.Write Chr(AscB(MidB(m_Blob, lngLoop, 1)))<BR> Next<BR> objFSOFile.Close <BR> End Sub<BR>End Class<BR><BR><BR>********************************* ***********************<BR>This is second part..... save as test.asp please<BR>**************************************** ************<BR><BR>&#060;%@ Language=VBScript %&#062;<BR>&#060;!-- #include file="Upload.asp" --&#062;<BR>&#060;form method=post<BR> enctype="multipart/form-data"<BR> action=test.asp&#062;<BR>Your Name:<BR>&#060;input type=text name=YourName&#062;<BR><BR><BR>Your File:<BR>&#060;input type=file name=YourFile&#062;<BR><BR><BR>&#060;input type=submit name=submit value="Upload"&#062;<BR>&#060;/form&#062;<BR>&#060;HR&#062;<BR>&#060;%<BR>Dim objUpload, lngLoop<BR><BR>If Request.TotalBytes &#062; 0 Then<BR> Set objUpload = New clsUpload<BR>%&#062;<BR>File(s) Uploaded: &#060;%= objUpload.Files.Count %&#062;<BR><BR><BR><BR>&#060;%<BR> For lngLoop = 0 to objUpload.Files.Count - 1<BR> &#039If accessing this page annonymously,<BR> &#039the internet guest account must have<BR> &#039write permission to the path below.<BR> objUpload.Files.Item(lngLoop).Save "c:inetpubwwwroot estuploadupload"<BR>%&#062;<BR>Form Element Name:<BR>&#060;%= objUpload.Files.Key(lngLoop) %&#062;<BR><BR><BR>File Name: <BR>&#060;%= objUpload.Files.Item(lngLoop).FileName %&#062;<BR><BR><BR><BR>&#060;%<BR> Next<BR>%&#062;<BR>Other Form Element(s): &#060;%= objUpload.Form.Count %&#062;<BR><BR><BR><BR>&#060;%<BR> For lngLoop = 0 to objUpload.Form.Count - 1<BR>%&#062;<BR>Form Element Name:<BR>&#060;%= objUpload.Form.Key(lngLoop) %&#062;<BR><BR><BR>Form Element Value:<BR>&#060;%= objUpload.Form.Item(lngLoop) %&#062;<BR><BR><BR><BR>&#060;%<BR> Next<BR>End If<BR>%&#062;<BR><BR><BR><BR><BR><BR>

Posting Permissions

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