473,238 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

Uploading Files

I'm a bit of a newbie here. I've learned a lot from reading the posts you all have here. I need some help uploading files using an asp form.

I am using some code that I found from Jacob at asp101.com.
http://www.asp101.com/articles/jacob/scriptupload.asp

My three files are:
Syllabus.htm

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. </head><body>
  6. <table width="500" border="1" frame="box" rules="none" align="center" cellpadding="0" cellspacing="0">
  7. <FORM name="form" ENCTYPE="multipart/form-data" METHOD="POST" ACTION="uploadexmple.asp">
  8.  <tr><TD colspan="4"><strong>Upload syllabus (one file)</strong></td>
  9. </tr><tr><td colspan="4"><INPUT TYPE=FILE SIZE=50 NAME="FILE1"></td></tr><TR><td colspan="4">
  10.    <div align="right">
  11.      <input type="reset" name="reset" /><input type="submit" name="Action" value="Submit">
  12.    </div></TD>
  13. </TR></form></Table>
  14. </body>
  15. </html>
Upload.asp
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. Class FileUploader
  4.     Public  Files
  5.     Private mcolFormElem
  6.  
  7.     Private Sub Class_Initialize()
  8.         Set Files = Server.CreateObject("Scripting.Dictionary")
  9.         Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
  10.     End Sub
  11.  
  12.     Private Sub Class_Terminate()
  13.         If IsObject(Files) Then
  14.             Files.RemoveAll()
  15.             Set Files = Nothing
  16.         End If
  17.         If IsObject(mcolFormElem) Then
  18.             mcolFormElem.RemoveAll()
  19.             Set mcolFormElem = Nothing
  20.         End If
  21.     End Sub
  22.  
  23.     Public Property Get Form(sIndex)
  24.         Form = ""
  25.         If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
  26.     End Property
  27.  
  28.     Public Default Sub Upload()
  29.         Dim biData, sInputName
  30.         Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
  31.         Dim nPosFile, nPosBound
  32.  
  33.         biData = Request.BinaryRead(Request.TotalBytes)
  34.         nPosBegin = 1
  35.         nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
  36.  
  37.         If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
  38.  
  39.         vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
  40.         nDataBoundPos = InstrB(1, biData, vDataBounds)
  41.  
  42.         Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
  43.  
  44.             nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
  45.             nPos = InstrB(nPos, biData, CByteString("name="))
  46.             nPosBegin = nPos + 6
  47.             nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
  48.             sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
  49.             nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
  50.             nPosBound = InstrB(nPosEnd, biData, vDataBounds)
  51.  
  52.             If nPosFile <> 0 And  nPosFile < nPosBound Then
  53.                 Dim oUploadFile, sFileName
  54.                 Set oUploadFile = New UploadedFile
  55.  
  56.                 nPosBegin = nPosFile + 10
  57.                 nPosEnd =  InstrB(nPosBegin, biData, CByteString(Chr(34)))
  58.                 sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
  59.                 oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))
  60.  
  61.                 nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
  62.                 nPosBegin = nPos + 14
  63.                 nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
  64.  
  65.                 oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
  66.  
  67.                 nPosBegin = nPosEnd+4
  68.                 nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
  69.                 oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
  70.  
  71.                 If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
  72.             Else
  73.                 nPos = InstrB(nPos, biData, CByteString(Chr(13)))
  74.                 nPosBegin = nPos + 4
  75.                 nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
  76.                 If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
  77.             End If
  78.  
  79.             nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
  80.         Loop
  81.     End Sub
  82.  
  83.     'String to byte string conversion
  84.     Private Function CByteString(sString)
  85.         Dim nIndex
  86.         For nIndex = 1 to Len(sString)
  87.            CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
  88.         Next
  89.     End Function
  90.  
  91.     'Byte string to string conversion
  92.     Private Function CWideString(bsString)
  93.         Dim nIndex
  94.         CWideString =""
  95.         For nIndex = 1 to LenB(bsString)
  96.            CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1))) 
  97.         Next
  98.     End Function
  99. End Class
  100.  
  101. Class UploadedFile
  102.     Public ContentType
  103.     Public FileName
  104.     Public FileData
  105.  
  106.     Public Property Get FileSize()
  107.         FileSize = LenB(FileData)
  108.     End Property
  109.  
  110.     Public Sub SaveToDisk(sPath)
  111.         Dim oFS, oFile
  112.         Dim nIndex
  113.  
  114.         If sPath = "" Or FileName = "" Then Exit Sub
  115.         If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
  116.  
  117.         Set oFS = Server.CreateObject("Scripting.FileSystemObject")
  118.         If Not oFS.FolderExists(sPath) Then Exit Sub
  119.  
  120.         Set oFile = oFS.CreateTextFile(sPath & FileName, True)
  121.  
  122.         For nIndex = 1 to LenB(FileData)
  123.             oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
  124.         Next
  125.  
  126.         oFile.Close
  127.     End Sub
  128.  
  129.     Public Sub SaveToDatabase(ByRef oField)
  130.         If LenB(FileData) = 0 Then Exit Sub
  131.  
  132.         If IsObject(oField) Then
  133.             oField.AppendChunk FileData
  134.         End If
  135.     End Sub
  136.  
  137. End Class
  138. %>
& uploadexmple.asp

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <%Option Explicit%>
  3. <!-- #include file="upload.asp" -->
  4. <%
  5.  
  6. 'NOTE - YOU MUST HAVE VBSCRIPT v5.0 INSTALLED ON YOUR WEB SERVER
  7. '       FOR THIS LIBRARY TO FUNCTION CORRECTLY. YOU CAN OBTAIN IT
  8. '       FREE FROM MICROSOFT WHEN YOU INSTALL INTERNET EXPLORER 5.0
  9. '       OR LATER.
  10.  
  11.  
  12. ' Create the FileUploader
  13. Dim Uploader, File, Pathhtm
  14. Set Uploader = New FileUploader
  15.  
  16. ' This starts the upload process
  17. Uploader.Upload()
  18.  
  19. '******************************************
  20. ' Use [FileUploader object].Form to access 
  21. ' additional form variables submitted with
  22. ' the file upload(s). (used below)
  23. '******************************************
  24.  
  25.  
  26. ' Check if any files were uploaded
  27. If Uploader.Files.Count = 0 Then
  28.     Response.Write "File(s) not uploaded."
  29. Else
  30.     ' Loop through the uploaded files
  31.     For Each File In Uploader.Files.Items
  32.  
  33.     File.SaveToDisk "path to save to"        
  34.  
  35.  
  36.         ' Output the file details to the browser
  37.  
  38.         Response.Write "<strong>Success!</strong><br>"
  39.         Response.Write "File Uploaded: " & File.FileName & "<br>"
  40.  
  41.     Next
  42. End If
  43.  
  44.  %>
The problem I am having is that it only randomly works. For example, today I was successful at uploading a file that is 30KB, but failed with one that is 6MB and another that is 15KB.

Is there something I am missing? Any help would be really appreciated.
Jul 30 '09 #1
0 2647

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dickiedyce | last post by:
Hi there. I've spent the weekend getting ever more frustrated, trying to get an upload file function working on a website. The site is hosted by a company called oneandone. They're using PHP...
5
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of...
5
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
0
by: Raj | last post by:
Hello, I am planning to provide the Pause/Resume while uploading files. Our site is using both java applet and activex to do this. The list of selected files will be stored in an encrypted...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
2
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
jodleren escribió: I haven't found the PHP manual page where such feature is documented but a few tests have shown that this behaviour changes depending on the charset parameter of the...
1
by: =?Utf-8?B?RGFu?= | last post by:
MS won't seem to let me reply to my old post, so I created a new one. The error occurs in all browsers. It's definitely a server issue, not client. The server is not proxied in any way. I tried...
3
by: muziburrehaman | last post by:
i am looking for code in php to upload the 1 gb files. any one can please help me by sending the code....
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.